Skip to content

Commit

Permalink
go-fuzz: don't drop data when Read also returns an error
Browse files Browse the repository at this point in the history
The io.Reader contract specifies that Read may
return n > 0 and err != nil, and that in that scenario,
the caller should process those n bytes.

This is rare enough that it probably wasn't causing an actual problem.

Fix it nevertheless; one fewer latent bug.
  • Loading branch information
josharian committed Mar 5, 2019
1 parent 5536980 commit 77a1f72
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions go-fuzz/testee.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ retry:
case <-t.downC:
}
n, err := t.stdoutPipe.Read(data[filled:])
if err != nil {
break
}
if *flagV >= 3 {
log.Printf("testee: %v\n", string(data[filled:filled+n]))
}
Expand All @@ -209,6 +206,9 @@ retry:
copy(data, data[testeeBufferSize/2:filled])
filled -= testeeBufferSize / 2
}
if err != nil {
break
}
}
ticker.Stop()
trimmed := make([]byte, filled)
Expand Down

0 comments on commit 77a1f72

Please sign in to comment.