From a08377f9cf6868af956dfdddc5753cdcdf7fc623 Mon Sep 17 00:00:00 2001 From: Micah Snyder Date: Tue, 18 Apr 2023 14:53:57 -0700 Subject: [PATCH] Coverity-344513: Fix use-after-free in unit test error condition. --- unit_tests/check_clamav.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unit_tests/check_clamav.c b/unit_tests/check_clamav.c index 045591ed6..61ecd8ad3 100644 --- a/unit_tests/check_clamav.c +++ b/unit_tests/check_clamav.c @@ -2055,7 +2055,9 @@ int main(void) srunner_set_log(sr, OBJDIR PATHSEP "test.log"); if (freopen(OBJDIR PATHSEP "test-stderr.log", "w+", stderr) == NULL) { - fputs("Unable to redirect stderr!\n", stderr); + // The stderr FILE pointer may be closed by `freopen()` even if redirecting to the log file files. + // So we will output the error message to stdout instead. + fputs("Unable to redirect stderr!\n", stdout); } cl_debug();