From 2c41b52901331f5c761015af786a3976e225d779 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Mon, 13 Jun 2016 13:08:39 +0200 Subject: debug/tst-longjmp_chk2: Make signal handler more conservative [BZ #20248] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, printf needs more stack space than what is available with SIGSTKSZ. This commit use the the write system call directly instead. Also use sig_atomic_t for the “pass” variable (for general correctness), and restore signal handlers to their defaults, to avoid masking crashes. --- debug/tst-longjmp_chk2.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'debug') diff --git a/debug/tst-longjmp_chk2.c b/debug/tst-longjmp_chk2.c index dae9ca01e5..243568c32e 100644 --- a/debug/tst-longjmp_chk2.c +++ b/debug/tst-longjmp_chk2.c @@ -6,15 +6,25 @@ #include #include #include +#include #include #include #include +#include static jmp_buf mainloop; static sigset_t mainsigset; -static int pass; +static volatile sig_atomic_t pass; +static void +write_message (const char *message) +{ + ssize_t unused __attribute__ ((unused)); + for (int i = 0; i < pass; ++i) + unused = write (STDOUT_FILENO, " ", 1); + unused = write (STDOUT_FILENO, message, strlen (message)); +} static void stackoverflow_handler (int sig) @@ -25,11 +35,9 @@ stackoverflow_handler (int sig) pass++; assert (pass < 5); sigaltstack (NULL, &altstack); - /* Using printf is not really kosher in signal handlers but we know - it will work. */ - printf ("%*sin signal handler\n", pass, ""); + write_message ("in signal handler\n"); if (altstack.ss_flags & SS_ONSTACK) - printf ("%*son alternate stack\n", pass, ""); + write_message ("on alternate stack\n"); siglongjmp (mainloop, pass); } @@ -112,6 +120,11 @@ do_test (void) else printf ("disabling alternate stack succeeded \n"); + /* Restore the signal handlers, in case we trigger a crash after the + tests above. */ + signal (SIGBUS, SIG_DFL); + signal (SIGSEGV, SIG_DFL); + return 0; } -- cgit v1.2.1