aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/trace/pprof_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/trace/pprof_test.go')
-rw-r--r--src/cmd/trace/pprof_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/cmd/trace/pprof_test.go b/src/cmd/trace/pprof_test.go
index 6d18e7d5d1..ec5bbd6816 100644
--- a/src/cmd/trace/pprof_test.go
+++ b/src/cmd/trace/pprof_test.go
@@ -14,6 +14,7 @@ import (
"testing/synctest"
"time"
+ itrace "internal/trace"
"internal/trace/testtrace"
)
@@ -81,6 +82,31 @@ func TestSyscallProfile74850(t *testing.T) {
}
}
+// Regression test: pcsForStack must not panic when the stack has more than
+// pprofMaxStack (128) frames. Before the fix, pcs[i] was written before
+// checking i >= len(pcs), causing an index-out-of-range panic.
+func TestFillPCsOverflow(t *testing.T) {
+ var pcs [pprofMaxStack]uint64
+
+ // Build a stack with more frames than pprofMaxStack.
+ n := pprofMaxStack + 10
+ frames := make([]itrace.StackFrame, n)
+ for i := range frames {
+ frames[i].PC = uint64(0x1000 + i)
+ }
+ stack := itrace.MakeStack(frames)
+
+ // This must not panic.
+ pcsForStack(stack, &pcs)
+
+ // Verify the first pprofMaxStack entries were written correctly.
+ for i := 0; i < pprofMaxStack; i++ {
+ if pcs[i] != uint64(0x1000+i) {
+ t.Errorf("pcs[%d] = %#x, want %#x", i, pcs[i], 0x1000+i)
+ }
+ }
+}
+
func stat(t *testing.T) {
_, err := os.Stat(".")
if err != nil {