]> code.delx.au - gnu-emacs/commitdiff
Backtrace after malloc arena is corrupted
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 25 Feb 2015 00:34:13 +0000 (16:34 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 25 Feb 2015 00:35:03 +0000 (16:35 -0800)
Without this change, if the malloc arena is corrupted and then
'backtrace' is called, the backtrace can crash because 'backtrace'
calls 'malloc'.  For more, please see:
https://sourceware.org/ml/libc-alpha/2015-02/msg00678.html
* emacs.c (main): Initialize tables used by 'backtrace'.
* sysdep.c (emacs_backtrace): Document the newly used part of the API.

src/ChangeLog
src/emacs.c
src/sysdep.c

index 6ef5746daa2c4b8d24ed6b9438a64969a441e0a4..1f0781fef108834954412cd526adc19f03638f09 100644 (file)
@@ -1,3 +1,13 @@
+2015-02-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Backtrace after malloc arena is corrupted
+       Without this change, if the malloc arena is corrupted and then
+       'backtrace' is called, the backtrace can crash because 'backtrace'
+       calls 'malloc'.  For more, please see:
+       https://sourceware.org/ml/libc-alpha/2015-02/msg00678.html
+       * emacs.c (main): Initialize tables used by 'backtrace'.
+       * sysdep.c (emacs_backtrace): Document the newly used part of the API.
+
 2015-02-22  Jan Djärv  <jan.h.d@swipnet.se>
 
        * nsfns.m (Fx_frame_geometry): New function.
index 4a6d6badf286a2b90edb0e6d58702d9c7f52aa10..c2b698ba50be2b2a3aa6167a7c067780ce72f914 100644 (file)
@@ -884,6 +884,8 @@ main (int argc, char **argv)
 
   clearerr (stdin);
 
+  emacs_backtrace (-1);
+
 #if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
   /* Arrange to get warning messages as memory fills up.  */
   memory_warnings (0, malloc_warning);
index a2bda96192f5300ef8870e9bec4f01b50d2361fe..cb361ec2dc517ff59a9d7500ed2df8da43e14a36 100644 (file)
@@ -2147,7 +2147,17 @@ snprintf (char *buf, size_t bufsize, char const *format, ...)
 /* If a backtrace is available, output the top lines of it to stderr.
    Do not output more than BACKTRACE_LIMIT or BACKTRACE_LIMIT_MAX lines.
    This function may be called from a signal handler, so it should
-   not invoke async-unsafe functions like malloc.  */
+   not invoke async-unsafe functions like malloc.
+
+   If BACKTRACE_LIMIT is -1, initialize tables that 'backtrace' uses
+   but do not output anything.  This avoids some problems that can
+   otherwise occur if the malloc arena is corrupted before 'backtrace'
+   is called, since 'backtrace' may call malloc if the tables are not
+   initialized.
+
+   If the static variable THREAD_BACKTRACE_NPOINTERS is nonzero, a
+   fatal error has occurred in some other thread; generate a thread
+   backtrace instead, ignoring BACKTRACE_LIMIT.  */
 void
 emacs_backtrace (int backtrace_limit)
 {