From c5bb8e2399f55c09a98c66936940ba744b5841da Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 29 Dec 2013 23:13:20 +0000 Subject: tests: unify fortification handler logic We have multiple tests that copy & paste the same logic for disabling the fortification output. Let's unify this in the test-skeleton instead. Signed-off-by: Mike Frysinger --- debug/test-strcpy_chk.c | 26 ++++++-------------------- debug/tst-chk1.c | 21 ++------------------- debug/tst-longjmp_chk.c | 27 +++++++-------------------- 3 files changed, 15 insertions(+), 59 deletions(-) (limited to 'debug') diff --git a/debug/test-strcpy_chk.c b/debug/test-strcpy_chk.c index 62a581d190..0e683becf1 100644 --- a/debug/test-strcpy_chk.c +++ b/debug/test-strcpy_chk.c @@ -54,6 +54,10 @@ simple_strcpy_chk (char *dst, const char *src, size_t len) #include #include +static int test_main (void); +#define TEST_FUNCTION test_main () +#include "../test-skeleton.c" + volatile int chk_fail_ok; jmp_buf chk_fail_buf; @@ -266,28 +270,12 @@ Iteration %zd - different strings, %s (%zd, %zd, %zd)\n", } } -int +static int test_main (void) { size_t i; - struct sigaction sa; - sa.sa_handler = handler; - sa.sa_flags = 0; - sigemptyset (&sa.sa_mask); - - sigaction (SIGABRT, &sa, NULL); - - /* Avoid all the buffer overflow messages on stderr. */ - int fd = open (_PATH_DEVNULL, O_WRONLY); - if (fd == -1) - close (STDERR_FILENO); - else - { - dup2 (fd, STDERR_FILENO); - close (fd); - } - setenv ("LIBC_FATAL_STDERR_", "1", 1); + set_fortify_handler (handler); test_init (); @@ -365,5 +353,3 @@ test_main (void) do_random_tests (); return ret; } - -#include "../test-skeleton.c" diff --git a/debug/tst-chk1.c b/debug/tst-chk1.c index f0b86a0aa6..33931537cc 100644 --- a/debug/tst-chk1.c +++ b/debug/tst-chk1.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -119,23 +118,7 @@ int num2 = 987654; static int do_test (void) { - struct sigaction sa; - sa.sa_handler = handler; - sa.sa_flags = 0; - sigemptyset (&sa.sa_mask); - - sigaction (SIGABRT, &sa, NULL); - - /* Avoid all the buffer overflow messages on stderr. */ - int fd = open (_PATH_DEVNULL, O_WRONLY); - if (fd == -1) - close (STDERR_FILENO); - else - { - dup2 (fd, STDERR_FILENO); - close (fd); - } - setenv ("LIBC_FATAL_STDERR_", "1", 1); + set_fortify_handler (handler); struct A { char buf1[9]; char buf2[1]; } a; struct wA { wchar_t buf1[9]; wchar_t buf2[1]; } wa; @@ -1366,7 +1349,7 @@ do_test (void) ret = 1; } - fd = posix_openpt (O_RDWR); + int fd = posix_openpt (O_RDWR); if (fd != -1) { char enough[1000]; diff --git a/debug/tst-longjmp_chk.c b/debug/tst-longjmp_chk.c index dba1855f4a..e4e93d2a36 100644 --- a/debug/tst-longjmp_chk.c +++ b/debug/tst-longjmp_chk.c @@ -10,6 +10,12 @@ #include #include + +static int do_test(void); +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" + + static jmp_buf b; @@ -48,23 +54,7 @@ handler (int sig) static int do_test (void) { - struct sigaction sa; - sa.sa_handler = handler; - sa.sa_flags = 0; - sigemptyset (&sa.sa_mask); - - sigaction (SIGABRT, &sa, NULL); - - /* Avoid all the buffer overflow messages on stderr. */ - int fd = open (_PATH_DEVNULL, O_WRONLY); - if (fd == -1) - close (STDERR_FILENO); - else - { - dup2 (fd, STDERR_FILENO); - close (fd); - } - setenv ("LIBC_FATAL_STDERR_", "1", 1); + set_fortify_handler (handler); expected_to_fail = false; @@ -86,6 +76,3 @@ do_test (void) puts ("second longjmp returned"); return 1; } - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" -- cgit v1.2.1