diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | assert/assert-perr.c | 10 | ||||
-rw-r--r-- | assert/assert.c | 11 | ||||
-rw-r--r-- | include/stdlib.h | 3 | ||||
-rw-r--r-- | stdlib/Versions | 2 | ||||
-rw-r--r-- | stdlib/abort.c | 6 | ||||
-rw-r--r-- | sysdeps/posix/libc_fatal.c | 17 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/libc_fatal.c | 18 |
8 files changed, 67 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog index 9e13cb7945..6c97032c14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2009-06-15 Ulrich Drepper <drepper@redhat.com> + [BZ #10217] + * stdlib/abort.c: Define variable __abort_msg. + * stdlib/Versions: Export __abort_msg with GLIBC_PRIVATE version. + * include/stdlib.h: Declare __abort_msg. + * assert/assert-perr.c: Don't free buffer for message immediately. + Store atomically in __abort_msg and free old buffer if necessary. + * assert/assert.c: Likewise. + * sysdeps/posix/libc_fatal.c: Allocate buffer for message, copy it, + store pointer in __abort_msg, and possibly free old string. + * sysdeps/unix/sysv/linux/libc_fatal.c: Likewise. + * time/tzfile.c (__tzfile_read): Correct computation of tzspec_len. [BZ #10211] diff --git a/assert/assert-perr.c b/assert/assert-perr.c index dd54246360..f239fab86b 100644 --- a/assert/assert-perr.c +++ b/assert/assert-perr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994-1998,2001,2002,2005 Free Software Foundation, Inc. +/* Copyright (C) 1994-1998,2001,2002,2005,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -17,6 +17,7 @@ 02111-1307 USA. */ #include <assert.h> +#include <atomic.h> #include <libintl.h> #include <stdio.h> #include <stdlib.h> @@ -64,9 +65,10 @@ __assert_perror_fail (int errnum, (void) __fxprintf (NULL, "%s", buf); (void) fflush (stderr); - /* We have to free the buffer since the appplication might catch the - SIGABRT. */ - free (buf); + /* We have to free the old buffer since the application might + catch the SIGABRT signal. */ + char *old = atomic_exchange_acq (&__abort_msg, buf); + free (old); } else { diff --git a/assert/assert.c b/assert/assert.c index 0ef4ca62e4..727fb1446c 100644 --- a/assert/assert.c +++ b/assert/assert.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,1994-1996,1998,2001,2002,2005 +/* Copyright (C) 1991,1994-1996,1998,2001,2002,2005,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -18,6 +18,7 @@ 02111-1307 USA. */ #include <assert.h> +#include <atomic.h> #include <libintl.h> #include <stdio.h> #include <stdlib.h> @@ -43,6 +44,7 @@ extern const char *__progname; # include FATAL_PREPARE_INCLUDE #endif + #undef __assert_fail void __assert_fail (const char *assertion, const char *file, unsigned int line, @@ -64,9 +66,10 @@ __assert_fail (const char *assertion, const char *file, unsigned int line, (void) __fxprintf (NULL, "%s", buf); (void) fflush (stderr); - /* We have to free the buffer since the application might catch the - SIGABRT. */ - free (buf); + /* We have to free the old buffer since the application might + catch the SIGABRT signal. */ + char *old = atomic_exchange_acq (&__abort_msg, buf); + free (old); } else { diff --git a/include/stdlib.h b/include/stdlib.h index 883bc34d4a..d90e6ff4fe 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -221,6 +221,9 @@ extern int __qfcvt_r (long double __value, int __ndigit, extern void *__default_morecore (ptrdiff_t) __THROW; libc_hidden_proto (__default_morecore) +extern char *__abort_msg; +libc_hidden_proto (__abort_msg) + __END_DECLS #undef __Need_M_And_C diff --git a/stdlib/Versions b/stdlib/Versions index 93c68f6e31..3e7b8921c4 100644 --- a/stdlib/Versions +++ b/stdlib/Versions @@ -104,5 +104,7 @@ libc { # functions which have an additional interface since they are # are cancelable. __libc_system; + # Variable which needs a dynamic symbol table entry. + __abort_msg; } } diff --git a/stdlib/abort.c b/stdlib/abort.c index 00788f22c7..3c188c9516 100644 --- a/stdlib/abort.c +++ b/stdlib/abort.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,93,95,96,97,98,2001,02 Free Software Foundation, Inc. +/* Copyright (C) 1991,93,1995-1998,2001,02,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -36,6 +36,10 @@ # define fflush(s) _IO_flush_all_lockp (0) #endif +/* Exported variable to locate abort message in core files etc. */ +char *__abort_msg __attribute__ ((nocommon)); +libc_hidden_def (__abort_msg) + /* We must avoid to run in circles. Therefore we remember how far we already got. */ static int stage; diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index c611b84363..4f11c0fcb0 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1994,1995,1997,2000,2004,2005 +/* Copyright (C) 1993-1995,1997,2000,2004,2005,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -17,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <atomic.h> #include <errno.h> #include <fcntl.h> #include <paths.h> @@ -123,6 +124,20 @@ __libc_message (int do_abort, const char *fmt, ...) if (TEMP_FAILURE_RETRY (__writev (fd, iov, nlist)) == total) written = true; + + char *buf = do_abort ? malloc (total + 1) : NULL; + if (buf != NULL) + { + char *wp = buf; + for (int cnt = 0; cnt < nlist; ++cnt) + wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len); + *wp = '\0'; + + /* We have to free the old buffer since the application might + catch the SIGABRT signal. */ + char *old = atomic_exchange_acq (&__abort_msg, buf); + free (old); + } } va_end (ap); diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c index c7fac6ab51..7287f4ef6c 100644 --- a/sysdeps/unix/sysv/linux/libc_fatal.c +++ b/sysdeps/unix/sysv/linux/libc_fatal.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1993-1995,1997,2000,2002-2005 Free Software Foundation, Inc. +/* Copyright (C) 1993-1995,1997,2000,2002-2005,2009 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <atomic.h> #include <errno.h> #include <fcntl.h> #include <paths.h> @@ -131,6 +133,20 @@ __libc_message (int do_abort, const char *fmt, ...) if (cnt == total) written = true; + + char *buf = do_abort ? malloc (total + 1) : NULL; + if (buf != NULL) + { + char *wp = buf; + for (int cnt = 0; cnt < nlist; ++cnt) + wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len); + *wp = '\0'; + + /* We have to free the old buffer since the application might + catch the SIGABRT signal. */ + char *old = atomic_exchange_acq (&__abort_msg, buf); + free (old); + } } va_end (ap); |