]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] internal/fuzz: add sharedMem.setValueLen
authorJay Conrod <jayconrod@google.com>
Thu, 14 Jan 2021 23:22:41 +0000 (18:22 -0500)
committerJay Conrod <jayconrod@google.com>
Fri, 15 Jan 2021 14:30:24 +0000 (14:30 +0000)
This method sets the len of the slice returned by valueRef. The worker
now uses this instead of setting the length in the header directly.

Unfortunately, we can't store the whole slice header in the shared
memory header because the pointer won't be valid across processes.

Change-Id: Icef24acfcd85e098cd8c23810568f04b13649a19
Reviewed-on: https://go-review.googlesource.com/c/go/+/284012
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
src/internal/fuzz/mem.go
src/internal/fuzz/worker.go

index 663598bb486d99cf2a499d67cb3815d82c6c50f5..bb30241a45b4123f3e08672838b37089a4c90495 100644 (file)
@@ -106,6 +106,20 @@ func (m *sharedMem) setValue(b []byte) {
        copy(v[:cap(v)], b)
 }
 
+// setValueLen sets the length of the shared memory buffer returned by valueRef
+// to n, which may be at most the cap of that slice.
+//
+// Note that we can only store the length in the shared memory header. The full
+// slice header contains a pointer, which is likely only valid for one process,
+// since each process can map shared memory at a different virtual address.
+func (m *sharedMem) setValueLen(n int) {
+       v := m.valueRef()
+       if n > cap(v) {
+               panic(fmt.Sprintf("length %d larger than shared memory capacity %d", n, cap(v)))
+       }
+       m.header().length = n
+}
+
 // TODO(jayconrod): add method to resize the buffer. We'll need that when the
 // mutator can increase input length. Only the coordinator will be able to
 // do it, since we'll need to send a message to the worker telling it to
index ee31ff43c6c27e9e16c859ab02a30a48e121fd5c..583e8f25c12630557964881312838b53c4176899 100644 (file)
@@ -444,10 +444,8 @@ func (ws *workerServer) fuzz(ctx context.Context, args fuzzArgs) fuzzResponse {
                default:
                        b := ws.mem.valueRef()
                        ws.m.mutate(&b)
-                       // TODO(jayconrod): consider making ws.m.header() contain the whole
-                       // slice header, so the length can be updated when the slice changes
-                       ws.mem.header().length = len(b)
-                       if err := ws.fuzzFn(ws.mem.valueRef()); err != nil {
+                       ws.mem.setValueLen(len(b))
+                       if err := ws.fuzzFn(b); err != nil {
                                return fuzzResponse{Err: err.Error()}
                        }
                        // TODO(jayconrod,katiehockman): return early if we find an