crt: test: Fix use-after-free crash in t_tsearch.c The test t_tsearch.c is crashing on Windows XP. Function twalk() invokes twalk() in infinite recursion which cause stack overflow. The reason is that tdestroy() frees the memory for the root node which invalidates root pointer and accessing it later cause use-after-free error. Seems that msvcrt memory allocator on Windows XP can trigger this crash more often than on other Windows versions. Fix this issue, after the tdestroy() call, sets the root node pointer to NULL. Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/testcases/Makefile.am b/mingw-w64-crt/testcases/Makefile.am index b8cdbae..2c0cce2 100644 --- a/mingw-w64-crt/testcases/Makefile.am +++ b/mingw-w64-crt/testcases/Makefile.am
@@ -294,8 +294,7 @@ t_excpt_int_divzero_thrd \ t_excpt_int_overflow \ t_excpt_int_overflow_thrd \ - t_nullptrexception \ - t_tsearch + t_nullptrexception # Include the complex math testcase fragment. include complex/Makefile.am
diff --git a/mingw-w64-crt/testcases/t_tsearch.c b/mingw-w64-crt/testcases/t_tsearch.c index 4965259..91c0de5 100644 --- a/mingw-w64-crt/testcases/t_tsearch.c +++ b/mingw-w64-crt/testcases/t_tsearch.c
@@ -117,6 +117,7 @@ printf("----------\n"); tdestroy(root, noop_free); + root = NULL; printf("---------- tree after deletion of all nodes using tdestroy() only:\n"); nodes_printed = 0; twalk(root, print_node);