mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
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:
@ -18,8 +18,10 @@
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <malloc.h>
|
||||
#include <paths.h>
|
||||
#include <search.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@ -194,6 +196,32 @@ signal_handler (int sig __attribute__ ((unused)))
|
||||
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. */
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
|
Reference in New Issue
Block a user