aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-11-15 12:57:15 -0800
committerRuss Cox <rsc@golang.org>2009-11-15 12:57:15 -0800
commit091191336a10e09099810c93b12499f619cc2990 (patch)
treec1bcbed80cc8e74ee1090f5a5cd5e4a270542979
parenta3382315269db849edd2df068f78b59168c3b32f (diff)
downloadgo-091191336a10e09099810c93b12499f619cc2990.tar.gz
go-091191336a10e09099810c93b12499f619cc2990.zip
runtime: avoid crash in Caller
Fixes #176. R=r https://golang.org/cl/154146
-rw-r--r--src/pkg/runtime/386/traceback.c2
-rw-r--r--src/pkg/runtime/amd64/traceback.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/pkg/runtime/386/traceback.c b/src/pkg/runtime/386/traceback.c
index 307980eb97..febbb51d1e 100644
--- a/src/pkg/runtime/386/traceback.c
+++ b/src/pkg/runtime/386/traceback.c
@@ -42,7 +42,7 @@ traceback(byte *pc0, byte *sp, G *g)
if(f == nil) {
// dangerous, but poke around to see if it is a closure
// ADDL $xxx, SP; RET
- if(p != 0 && p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) {
+ if((uint64)pc > 0x1000 && p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) {
sp += *(uint32*)(p+2) + 8;
pc = *(uintptr*)(sp - 8);
if(pc <= 0x1000)
diff --git a/src/pkg/runtime/amd64/traceback.c b/src/pkg/runtime/amd64/traceback.c
index 7b0306f8c1..a260b7e4cc 100644
--- a/src/pkg/runtime/amd64/traceback.c
+++ b/src/pkg/runtime/amd64/traceback.c
@@ -127,7 +127,7 @@ runtime·Caller(int32 n, uint64 retpc, String retfile, int32 retline, bool retbo
// see if it is a closure.
p = (byte*)pc;
// ADDQ $xxx, SP; RET
- if(p[0] == 0x48 && p[1] == 0x81 && p[2] == 0xc4 && p[7] == 0xc3) {
+ if(pc > 0x1000 && p[0] == 0x48 && p[1] == 0x81 && p[2] == 0xc4 && p[7] == 0xc3) {
sp += *(uint32*)(p+3) + 8;
goto loop;
}