Skip to content

Commit 3d1c3e1

Browse files
committed
runtime: stack copier should handle nil defers without faulting.
fixes #8047 LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://golang.org/cl/101800043
1 parent bd401ba commit 3d1c3e1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/pkg/runtime/stack.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ copyabletopsegment(G *gp)
344344
if(d->argp < cinfo.stk || cinfo.base <= d->argp)
345345
break; // a defer for the next segment
346346
fn = d->fn;
347+
if(fn == nil) // See issue 8047
348+
continue;
347349
f = runtime·findfunc((uintptr)fn->fn);
348350
if(f == nil)
349351
return -1;
@@ -552,13 +554,19 @@ adjustdefers(G *gp, AdjustInfo *adjinfo)
552554
}
553555
if(d->argp < adjinfo->oldstk || adjinfo->oldbase <= d->argp)
554556
break; // a defer for the next segment
555-
f = runtime·findfunc((uintptr)d->fn->fn);
557+
fn = d->fn;
558+
if(fn == nil) {
559+
// Defer of nil function. It will panic when run, and there
560+
// aren't any args to adjust. See issue 8047.
561+
d->argp += adjinfo->delta;
562+
continue;
563+
}
564+
f = runtime·findfunc((uintptr)fn->fn);
556565
if(f == nil)
557566
runtime·throw("can't adjust unknown defer");
558567
if(StackDebug >= 4)
559568
runtime·printf(" checking defer %s\n", runtime·funcname(f));
560569
// Defer's FuncVal might be on the stack
561-
fn = d->fn;
562570
if(adjinfo->oldstk <= (byte*)fn && (byte*)fn < adjinfo->oldbase) {
563571
if(StackDebug >= 3)
564572
runtime·printf(" adjust defer fn %s\n", runtime·funcname(f));

0 commit comments

Comments
 (0)