aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2021-09-14 12:40:10 -0700
committerRoland Shoemaker <roland@golang.org>2021-09-22 15:38:34 +0000
commitccf140f3d79248f5dc5e326b0d2942aa4ba70b98 (patch)
tree09361aa63121ce59d9e249120f9ff0136e530832 /src/testing
parent91c2318e67da2e5948cd8ed0420863af69142c3d (diff)
downloadgo-ccf140f3d79248f5dc5e326b0d2942aa4ba70b98.tar.xz
internal/fuzz: allocate memory for mutated strings
Rather than directly pointing at the underlying scratch slice, allocate memory for strings. This prevents mutation of previous values we've passed to the fuzz function, which may be retained by something that expects them to be immutable. Fixes golang/go#48308 Change-Id: Iee9bed1a536fdc4188180e8e7c1c722f641271d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/351312 Trust: Roland Shoemaker <roland@golang.org> Trust: Katie Hockman <katie@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Katie Hockman <katie@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/fuzz.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go
index 57ea418039..ddce065783 100644
--- a/src/testing/fuzz.go
+++ b/src/testing/fuzz.go
@@ -293,7 +293,10 @@ var supportedTypes = map[reflect.Type]bool{
// f.Fuzz(func(t *testing.T, b []byte, i int) { ... })
//
// This function should be fast, deterministic, and stateless.
-// None of the pointers to any input data should be retained between executions.
+//
+// No mutatable input arguments, or pointers to them, should be retained between
+// executions of the fuzz function, as the memory backing them may be mutated
+// during a subsequent invocation.
//
// This is a terminal function which will terminate the currently running fuzz
// target by calling runtime.Goexit.