From patchwork Tue Jun 2 20:29:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tulio Magno Quites Machado Filho X-Patchwork-Id: 7016 Received: (qmail 90889 invoked by alias); 2 Jun 2015 20:30:06 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 90812 invoked by uid 89); 2 Jun 2015 20:30:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: e24smtp05.br.ibm.com From: "Tulio Magno Quites Machado Filho" To: siddhesh@redhat.com Cc: libc-alpha@sourceware.org Subject: [PATCH] Avoid outputting to TTY after an expected memory corruption in testcase Date: Tue, 2 Jun 2015 17:29:34 -0300 Message-Id: <1433276974-18370-1-git-send-email-tuliom@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15060220-0033-0000-0000-000002AF12DE Protect TTY against an expected memory corruption from testcase tst-malloc-backtrace, which is expected to SIGABRT after a forced memory corruption. 2015-06-02 Tulio Magno Quites Machado Filho * malloc/tst-malloc-backtrace.c(do_test): Redirect libc fatal errors to stderr. --- malloc/tst-malloc-backtrace.c | 15 ++++++++++----- test-skeleton.c | 28 +++++++++++++++++----------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/malloc/tst-malloc-backtrace.c b/malloc/tst-malloc-backtrace.c index 2e24157..7b317bb 100644 --- a/malloc/tst-malloc-backtrace.c +++ b/malloc/tst-malloc-backtrace.c @@ -30,12 +30,22 @@ call_free (void *ptr) *(size_t *)(ptr - sizeof (size_t)) = 1; } +int do_test (void); + +#define TEST_FUNCTION do_test () +#define EXPECTED_SIGNAL SIGABRT + +#include "../test-skeleton.c" + int do_test (void) { void *ptr1 = malloc (SIZE); void *ptr2 = malloc (SIZE); + /* Avoid unwanted output to TTY after an expected memory corruption. */ + ignore_stderr(); + call_free (ptr1); ptr1 = malloc (SIZE); @@ -43,8 +53,3 @@ do_test (void) doesn't optimize out that malloc call. */ return (ptr1 == ptr2); } - -#define TEST_FUNCTION do_test () -#define EXPECTED_SIGNAL SIGABRT - -#include "../test-skeleton.c" diff --git a/test-skeleton.c b/test-skeleton.c index 1332c94..9ee5001 100644 --- a/test-skeleton.c +++ b/test-skeleton.c @@ -218,6 +218,22 @@ signal_handler (int sig __attribute__ ((unused))) exit (1); } +/* Avoid all the buffer overflow messages on stderr. */ +static void +__attribute__ ((unused)) +ignore_stderr (void) +{ + 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 fortification error handler. Used when tests want to verify that bad code is caught by the library. */ static void @@ -231,17 +247,7 @@ set_fortify_handler (void (*handler) (int sig)) 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); + ignore_stderr (); } /* We provide the entry point here. */