]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix stack size check
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 13 Mar 2014 09:16:02 +0000 (13:16 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 13 Mar 2014 09:16:02 +0000 (13:16 +0400)
When we copy stack, we check only new size of the top segment.
This is incorrect, because we can have other segments below it.

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

src/pkg/runtime/stack.c

index 4bdc24107c82543e943f00ae9913b1a878596e5d..bb7a32f8ae7a1dbe54fb84e6872325de8cfdc0d7 100644 (file)
@@ -662,13 +662,13 @@ runtime·newstack(void)
                        oldbase = (byte*)gp->stackbase + sizeof(Stktop);
                        oldsize = oldbase - oldstk;
                        newsize = oldsize * 2;
-                       if(newsize > runtime·maxstacksize) {
-                               runtime·printf("runtime: goroutine stack exceeds %D-byte limit\n", (uint64)runtime·maxstacksize);
-                               runtime·throw("stack overflow");
-                       }
                        copystack(gp, nframes, newsize);
                        if(StackDebug >= 1)
                                runtime·printf("stack grow done\n");
+                       if(gp->stacksize > runtime·maxstacksize) {
+                               runtime·printf("runtime: goroutine stack exceeds %D-byte limit\n", (uint64)runtime·maxstacksize);
+                               runtime·throw("stack overflow");
+                       }
                        gp->status = oldstatus;
                        runtime·gogo(&gp->sched);
                }