diff mbox

libgo patch committed: Don't crash if crashing on signal due to heap corruption

Message ID CAOyqgcU07e0rafi7nW=0a2cx2JyJ6wPo4UooX+8==OsQyNe13A@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor March 9, 2015, 11:41 p.m. UTC
Previously, if a Go program was crashing due to a signal due to heap
corruption, it could in some cases invoke the Go malloc function while
the Go malloc lock was held, leading to a recursive crash.  This patch
fixes the problem by making __go_file_line simply assume that
libbacktrace keeps strings in memory, as runtime.Callers already does.
This error showed in PR 65349.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r 2169f7d99472 libgo/runtime/go-caller.c
--- a/libgo/runtime/go-caller.c	Fri Mar 06 08:17:57 2015 -0800
+++ b/libgo/runtime/go-caller.c	Mon Mar 09 16:21:20 2015 -0700
@@ -37,36 +37,12 @@ 
 {
   struct caller *c = (struct caller *) data;
 
-  if (function == NULL)
-    {
-      c->fn.str = NULL;
-      c->fn.len = 0;
-    }
-  else
-    {
-      byte *s;
-
-      c->fn.len = __builtin_strlen (function);
-      s = runtime_malloc (c->fn.len);
-      __builtin_memcpy (s, function, c->fn.len);
-      c->fn.str = s;
-    }
-
-  if (filename == NULL)
-    {
-      c->file.str = NULL;
-      c->file.len = 0;
-    }
-  else
-    {
-      byte *s;
-
-      c->file.len = __builtin_strlen (filename);
-      s = runtime_malloc (c->file.len);
-      __builtin_memcpy (s, filename, c->file.len);
-      c->file.str = s;
-    }
-
+  /* The libbacktrace library says that these strings might disappear,
+     but with the current implementation they won't.  We can't easily
+     allocate memory here, so for now assume that we can save a
+     pointer to the strings.  */
+  c->fn = runtime_gostringnocopy ((const byte *) function);
+  c->file = runtime_gostringnocopy ((const byte *) filename);
   c->line = lineno;
 
   return 0;