]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix go of nil func value
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 28 May 2014 04:00:01 +0000 (00:00 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 28 May 2014 04:00:01 +0000 (00:00 -0400)
Currently runtime derefences nil with m->locks>0,
which causes unrecoverable fatal error.
Panic instead.
Fixes #8045.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews, khr
https://golang.org/cl/97620043

src/pkg/runtime/crash_test.go
src/pkg/runtime/proc.c

index b2e846a187a2f5e37f5914ef2d91735368c5e596..b0277f293cbd1de5ea215a8f75917df26503bc98 100644 (file)
@@ -158,6 +158,14 @@ func TestGoexitCrash(t *testing.T) {
        }
 }
 
+func TestGoNil(t *testing.T) {
+       output := executeTest(t, goNilSource, nil)
+       want := "go of nil func value"
+       if !strings.Contains(output, want) {
+               t.Fatalf("output:\n%s\n\nwant output containing: %s", output, want)
+       }
+}
+
 const crashSource = `
 package main
 
@@ -343,3 +351,16 @@ func main() {
        runtime.Goexit()
 }
 `
+
+const goNilSource = `
+package main
+
+func main() {
+       defer func() {
+               recover()
+       }()
+       var f func()
+       go f()
+       select{}
+}
+`
index 7500e8a5f9db2a1afb2d749dd90a18e42cdaca12..fc52e09230a2bad0cfbfd6d4e42d0a531ef1a9bb 100644 (file)
@@ -1816,6 +1816,10 @@ runtime·newproc1(FuncVal *fn, byte *argp, int32 narg, int32 nret, void *callerp
        int32 siz;
 
 //runtime·printf("newproc1 %p %p narg=%d nret=%d\n", fn->fn, argp, narg, nret);
+       if(fn == nil) {
+               m->throwing = -1;  // do not dump full stacks
+               runtime·throw("go of nil func value");
+       }
        m->locks++;  // disable preemption because it can be holding p in a local var
        siz = narg + nret;
        siz = (siz+7) & ~7;