Fix BZ #18084 (backtrace(..., 0) crash on x86)
Paul Pluzhnikov
ppluzhnikov@gmail.com
Mon Aug 10 00:04:00 GMT 2015
Greetings,
This patch fixes BZ #18084 -- crash in backtrace(..., 0) on x86.
Tested on Linux/x86, no new failures.
Thanks,
2015-08-09 Paul Pluzhnikov <ppluzhnikov@google.com>
* sysdeps/i386/backtrace.c (__backtrace): Handle size==0.
* debug/tst-backtrace2.c (do_test): Add test for BZ #18084.
--
Paul Pluzhnikov
-------------- next part --------------
diff --git a/debug/tst-backtrace2.c b/debug/tst-backtrace2.c
index 846ca35..396d743 100644
--- a/debug/tst-backtrace2.c
+++ b/debug/tst-backtrace2.c
@@ -94,6 +94,12 @@ fn3 (void)
NO_INLINE static int
do_test (void)
{
+ /* Test BZ #18084. */
+ void *buffer[1];
+
+ if (backtrace (buffer, 0) != 0)
+ FAIL ();
+
fn3 ();
return ret;
}
diff --git a/sysdeps/i386/backtrace.c b/sysdeps/i386/backtrace.c
index 550234f..a0eff81 100644
--- a/sysdeps/i386/backtrace.c
+++ b/sysdeps/i386/backtrace.c
@@ -122,8 +122,10 @@ __backtrace (array, size)
return 0;
#endif
- if (size >= 1)
- unwind_backtrace (backtrace_helper, &arg);
+ if (size <= 0)
+ return 0;
+
+ unwind_backtrace (backtrace_helper, &arg);
if (arg.cnt > 1 && arg.array[arg.cnt - 1] == NULL)
--arg.cnt;
More information about the Libc-alpha
mailing list