]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: guard against array out of bounds in GoroutineProfile
authorRuss Cox <rsc@golang.org>
Wed, 27 Jan 2016 04:00:41 +0000 (23:00 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 27 Jan 2016 04:56:32 +0000 (04:56 +0000)
The previous CL is the real fix. This one is just insurance.

Fixes #14046 again.

Change-Id: I553349504bb1789e4b66c888dbe4034568918ad6
Reviewed-on: https://go-review.googlesource.com/18977
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/mprof.go

index e45bc7a7701aa9b43e4a638c594d751055758cd8..fc73bbfbe1531a51051a7b59e310d1739340f74e 100644 (file)
@@ -554,6 +554,11 @@ func GoroutineProfile(p []StackRecord) (n int, ok bool) {
                // Save other goroutines.
                for _, gp1 := range allgs {
                        if isOK(gp1) {
+                               if len(r) == 0 {
+                                       // Should be impossible, but better to return a
+                                       // truncated profile than to crash the entire process.
+                                       break
+                               }
                                saveg(^uintptr(0), ^uintptr(0), gp1, &r[0])
                                r = r[1:]
                        }