Skip to content

Commit 0911913

Browse files
committed
runtime: avoid crash in Caller
Fixes #176. R=r https://golang.org/cl/154146
1 parent a338231 commit 0911913

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/pkg/runtime/386/traceback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ traceback(byte *pc0, byte *sp, G *g)
4242
if(f == nil) {
4343
// dangerous, but poke around to see if it is a closure
4444
// ADDL $xxx, SP; RET
45-
if(p != 0 && p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) {
45+
if((uint64)pc > 0x1000 && p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) {
4646
sp += *(uint32*)(p+2) + 8;
4747
pc = *(uintptr*)(sp - 8);
4848
if(pc <= 0x1000)

src/pkg/runtime/amd64/traceback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ runtime·Caller(int32 n, uint64 retpc, String retfile, int32 retline, bool retbo
127127
// see if it is a closure.
128128
p = (byte*)pc;
129129
// ADDQ $xxx, SP; RET
130-
if(p[0] == 0x48 && p[1] == 0x81 && p[2] == 0xc4 && p[7] == 0xc3) {
130+
if(pc > 0x1000 && p[0] == 0x48 && p[1] == 0x81 && p[2] == 0xc4 && p[7] == 0xc3) {
131131
sp += *(uint32*)(p+3) + 8;
132132
goto loop;
133133
}

0 commit comments

Comments
 (0)