Commit b5caa020 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov Committed by Russ Cox

runtime: fix go of nil func value

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
parent 8a2db409
......@@ -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{}
}
`
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment