Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Preserve message printed before abort.
The terminal output etc is not visible in a core file.  The new
libc-internal variable __abort_msg will point to a string with the
message which has been printed before the abort in case abort is
called from inside libc.  BZ #10217
  • Loading branch information
Ulrich Drepper committed Jun 15, 2009
1 parent 6355c99 commit 48dcd0b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 11 deletions.
11 changes: 11 additions & 0 deletions 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]
Expand Down
10 changes: 6 additions & 4 deletions 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
Expand All @@ -17,6 +17,7 @@
02111-1307 USA. */

#include <assert.h>
#include <atomic.h>
#include <libintl.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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
{
Expand Down
11 changes: 7 additions & 4 deletions 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.
Expand All @@ -18,6 +18,7 @@
02111-1307 USA. */

#include <assert.h>
#include <atomic.h>
#include <libintl.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -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,
Expand All @@ -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
{
Expand Down
3 changes: 3 additions & 0 deletions include/stdlib.h
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Versions
Expand Up @@ -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;
}
}
6 changes: 5 additions & 1 deletion 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
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion 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.
Expand All @@ -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>
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion 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
Expand All @@ -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>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 48dcd0b

Please sign in to comment.