From: Paul Eggert Date: Fri, 19 May 2017 15:52:38 +0000 (-0700) Subject: closeout: don’t close stderr when sanitizing X-Git-Tag: v1.0~6133 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=105ff45093137b71507172d426837414ce1b7668;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 3dce45ea6b..4794685a91 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 bd40347174..b75ca01427 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 a23388f9c7..2a3f79152d 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); }