>From db389c44582a7e5b3aab9669cf3256d842a9d64c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 19 May 2017 08:52:38 -0700 Subject: [PATCH] =?UTF-8?q?closeout:=20don=E2=80=99t=20close=20stderr=20wh?= =?UTF-8?q?en=20sanitizing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * NEWS: Document this. * lib/closeout.c (__has_feature): New macro, if not already defined. (SANITIZE_ADDRESS): New constant. (close_stdout): Don’t close stderr if sanitizing addresses. --- ChangeLog | 8 ++++++++ NEWS | 4 ++++ lib/closeout.c | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3dce45e..4794685 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2017-05-19 Paul Eggert + + closeout: don’t close stderr when sanitizing + * NEWS: Document this. + * lib/closeout.c (__has_feature): New macro, if not already defined. + (SANITIZE_ADDRESS): New constant. + (close_stdout): Don’t close stderr if sanitizing addresses. + 2017-05-19 Bruno Haible get-rusage-data tests: Avoid failure on Linux/glibc. diff --git a/NEWS b/NEWS index bd40347..b75ca01 100644 --- a/NEWS +++ b/NEWS @@ -42,6 +42,10 @@ User visible incompatible changes Date Modules Changes +2017-05-19 closeout close_stdout longer closes stderr when addresses + are being sanitized, as the sanitizer outputs to + stderr afterwards. + 2017-02-16 binary-io On MS-DOS and OS/2, set_binary_mode now fails on ttys, and sets errno == EINVAL. diff --git a/lib/closeout.c b/lib/closeout.c index a23388f..2a3f791 100644 --- a/lib/closeout.c +++ b/lib/closeout.c @@ -33,6 +33,16 @@ #include "exitfail.h" #include "quotearg.h" +#ifndef __has_feature +# define __has_feature(a) false +#endif + +#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +enum { SANITIZE_ADDRESS = true }; +#else +enum { SANITIZE_ADDRESS = false }; +#endif + static const char *file_name; /* Set the file name to be reported in the event an error is detected @@ -119,6 +129,8 @@ close_stdout (void) _exit (exit_failure); } - if (close_stream (stderr) != 0) - _exit (exit_failure); + /* Close stderr only if not sanitizing, as sanitizers may report to + stderr after this function returns. */ + if (!SANITIZE_ADDRESS && close_stream (stderr) != 0) + _exit (exit_failure); } -- 2.9.4