]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid crash in Caller
authorRuss Cox <rsc@golang.org>
Sun, 15 Nov 2009 20:57:15 +0000 (12:57 -0800)
committerRuss Cox <rsc@golang.org>
Sun, 15 Nov 2009 20:57:15 +0000 (12:57 -0800)
Fixes #176.

R=r
https://golang.org/cl/154146

src/pkg/runtime/386/traceback.c
src/pkg/runtime/amd64/traceback.c

index 307980eb9766273fbe0f00f506e7a4cca62c47df..febbb51d1e9fe848759ec923c520d7624f6efe4c 100644 (file)
@@ -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)
index 7b0306f8c1f9d5e1d9b6cac3a03b433f3de9d917..a260b7e4cc8a3ca987d1b8ccbc64b961887342bd 100644 (file)
@@ -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;
                        }