From d759ed527c7c75cffcc9b72dd7b3fcf0854bec2f Mon Sep 17 00:00:00 2001 From: Chris Down Date: Wed, 19 Nov 2025 21:45:40 +0800 Subject: [PATCH] tests: ASSERT_SIGNAL: Ensure sanitisers do not mask expected signals ASAN installs signal handlers to catch crashes like SIGSEGV or SIGILL. When these signals are raised, ASAN traps them, prints an error report, and then typically terminates the process with a different signal (often SIGABRT) or a non-zero exit code. This interferes with ASSERT_SIGNAL when checking for specific crash signals (for example, checking that a function raises SIGSEGV). In such a case, the test harness sees the ASAN termination signal rather than the expected signal, causing the test to fail. Fix this by resetting the signal handler to SIG_DFL in the child process immediately before executing the test expression. This ensures the kernel kills the process directly with the expected signal, bypassing ASAN's interceptors. --- src/shared/tests.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/shared/tests.h b/src/shared/tests.h index 1605778fb6c..2aced042652 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -598,18 +598,19 @@ int assert_signal_internal(void); # define ASSERT_SIGNAL(expr, signal) __coverity_check__(((expr), false)) #else # define ASSERT_SIGNAL(expr, signal) __ASSERT_SIGNAL(UNIQ, expr, signal) -# define __ASSERT_SIGNAL(uniq, expr, signal) \ +# define __ASSERT_SIGNAL(uniq, expr, sgnl) \ ({ \ - ASSERT_TRUE(SIGNAL_VALID(signal)); \ + ASSERT_TRUE(SIGNAL_VALID(sgnl)); \ int UNIQ_T(_r, uniq) = assert_signal_internal(); \ ASSERT_OK_ERRNO(UNIQ_T(_r, uniq)); \ if (UNIQ_T(_r, uniq) == 0) { \ + (void) signal(sgnl, SIG_DFL); \ expr; \ _exit(EXIT_SUCCESS); \ } \ - if (UNIQ_T(_r, uniq) != signal) \ + if (UNIQ_T(_r, uniq) != sgnl) \ log_test_failed("\"%s\" died with signal %s, but %s was expected", \ - #expr, signal_to_string(UNIQ_T(_r, uniq)), signal_to_string(signal)); \ + #expr, signal_to_string(UNIQ_T(_r, uniq)), signal_to_string(sgnl)); \ }) #endif -- 2.47.3