From bcb66f3e32aa0eb23e408a4a3f8eab192c7ae0a0 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Tue, 19 Jun 2018 16:12:40 -0400 Subject: [PATCH] Check for strdup() failures in Check's unit tests If a strdup() fails a NULL pointer would be passed to mkstemp(), and it does not accept NULL pointers. This was discovered using scan-build. --- tests/check_check_master.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/check_check_master.c b/tests/check_check_master.c index 5aedc79..c529662 100644 --- a/tests/check_check_master.c +++ b/tests/check_check_master.c @@ -853,8 +853,10 @@ void setup (void) line_num_failures = fopen(line_num_failures_file_name, "w+b"); #else test_names_file_name = strdup("check_test_names__XXXXXX"); + assert(test_names_file_name != NULL && "strdup() failed"); test_names_file = fdopen(mkstemp(test_names_file_name), "w+b"); line_num_failures_file_name = strdup("check_error_linenums_XXXXXX"); + assert(line_num_failures_file_name != NULL && "strdup() failed"); line_num_failures = fdopen(mkstemp(line_num_failures_file_name), "w+b"); #endif -- 2.40.0