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 <vapier@gentoo.org>
This commit is contained in:
parent
10444e425e
commit
c5bb8e2399
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2014-02-08 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
|
* benchtests/bench-strcpy_chk.c: Move test-skeleton.c to top.
|
||||||
|
(test_main): Replace code with set_fortify_handler call.
|
||||||
|
* debug/test-strcpy_chk.c: Likewise.
|
||||||
|
* debug/tst-chk1.c: Likewise.
|
||||||
|
* debug/tst-longjmp_chk.c: Likewise.
|
||||||
|
* test-skeleton.c: Include fcntl.h & paths.h
|
||||||
|
(set_fortify_handler): Define.
|
||||||
|
|
||||||
2014-02-08 Mike Frysinger <vapier@gentoo.org>
|
2014-02-08 Mike Frysinger <vapier@gentoo.org>
|
||||||
|
|
||||||
* debug/tst-longjmp_chk.c: Add header comment and include
|
* debug/tst-longjmp_chk.c: Add header comment and include
|
||||||
|
|
|
@ -53,6 +53,9 @@ simple_strcpy_chk (char *dst, const char *src, size_t len)
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
static int test_main (void);
|
||||||
|
#include "../test-skeleton.c"
|
||||||
|
|
||||||
volatile int chk_fail_ok;
|
volatile int chk_fail_ok;
|
||||||
jmp_buf chk_fail_buf;
|
jmp_buf chk_fail_buf;
|
||||||
|
|
||||||
|
@ -156,28 +159,12 @@ do_test (size_t align1, size_t align2, size_t len, size_t dlen, int max_char)
|
||||||
putchar ('\n');
|
putchar ('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
test_main (void)
|
test_main (void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
struct sigaction sa;
|
set_fortify_handler (handler);
|
||||||
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);
|
|
||||||
|
|
||||||
test_init ();
|
test_init ();
|
||||||
|
|
||||||
|
@ -254,5 +241,3 @@ test_main (void)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "../test-skeleton.c"
|
|
||||||
|
|
|
@ -54,6 +54,10 @@ simple_strcpy_chk (char *dst, const char *src, size_t len)
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
static int test_main (void);
|
||||||
|
#define TEST_FUNCTION test_main ()
|
||||||
|
#include "../test-skeleton.c"
|
||||||
|
|
||||||
volatile int chk_fail_ok;
|
volatile int chk_fail_ok;
|
||||||
jmp_buf chk_fail_buf;
|
jmp_buf chk_fail_buf;
|
||||||
|
|
||||||
|
@ -266,28 +270,12 @@ Iteration %zd - different strings, %s (%zd, %zd, %zd)\n",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
test_main (void)
|
test_main (void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
struct sigaction sa;
|
set_fortify_handler (handler);
|
||||||
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);
|
|
||||||
|
|
||||||
test_init ();
|
test_init ();
|
||||||
|
|
||||||
|
@ -365,5 +353,3 @@ test_main (void)
|
||||||
do_random_tests ();
|
do_random_tests ();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "../test-skeleton.c"
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <obstack.h>
|
#include <obstack.h>
|
||||||
#include <paths.h>
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -119,23 +118,7 @@ int num2 = 987654;
|
||||||
static int
|
static int
|
||||||
do_test (void)
|
do_test (void)
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
set_fortify_handler (handler);
|
||||||
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);
|
|
||||||
|
|
||||||
struct A { char buf1[9]; char buf2[1]; } a;
|
struct A { char buf1[9]; char buf2[1]; } a;
|
||||||
struct wA { wchar_t buf1[9]; wchar_t buf2[1]; } wa;
|
struct wA { wchar_t buf1[9]; wchar_t buf2[1]; } wa;
|
||||||
|
@ -1366,7 +1349,7 @@ do_test (void)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = posix_openpt (O_RDWR);
|
int fd = posix_openpt (O_RDWR);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
char enough[1000];
|
char enough[1000];
|
||||||
|
|
|
@ -10,6 +10,12 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
static int do_test(void);
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
#include "../test-skeleton.c"
|
||||||
|
|
||||||
|
|
||||||
static jmp_buf b;
|
static jmp_buf b;
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,23 +54,7 @@ handler (int sig)
|
||||||
static int
|
static int
|
||||||
do_test (void)
|
do_test (void)
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
set_fortify_handler (handler);
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
expected_to_fail = false;
|
expected_to_fail = false;
|
||||||
|
@ -86,6 +76,3 @@ do_test (void)
|
||||||
puts ("second longjmp returned");
|
puts ("second longjmp returned");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_FUNCTION do_test ()
|
|
||||||
#include "../test-skeleton.c"
|
|
||||||
|
|
|
@ -18,8 +18,10 @@
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <search.h>
|
#include <search.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -194,6 +196,32 @@ signal_handler (int sig __attribute__ ((unused)))
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set fortification error handler. Used when tests want to verify that bad
|
||||||
|
code is caught by the library. */
|
||||||
|
static void
|
||||||
|
__attribute__ ((unused))
|
||||||
|
set_fortify_handler (void (*handler) (int sig))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/* We provide the entry point here. */
|
/* We provide the entry point here. */
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
|
|
Loading…
Reference in New Issue