Skip to content

Commit

Permalink
prog: fix out-of-bounds access
Browse files Browse the repository at this point in the history
ParseLog can access data out-of-bounds.
Fix that and fix regression fuzz tests to catch this.
  • Loading branch information
dvyukov committed Jul 30, 2019
1 parent 3b37734 commit 7c7ded6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,6 @@ func TestFuzz(t *testing.T) {
"cleaned vnod\re",
"kernel\r:",
} {
Fuzz([]byte(data))
Fuzz([]byte(data)[:len(data):len(data)])
}
}
2 changes: 1 addition & 1 deletion prog/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (target *Target) ParseLog(data []byte) []*LogEntry {
for pos := 0; pos < len(data); {
nl := bytes.IndexByte(data[pos:], '\n')
if nl == -1 {
nl = len(data)
nl = len(data) - 1
} else {
nl += pos
}
Expand Down
6 changes: 4 additions & 2 deletions prog/test/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ mutate4()
mutate7()
mutate8()
`,
`E`,
} {
t.Logf("test #%v: %q", i, data)
FuzzDeserialize([]byte(data))
FuzzParseLog([]byte(data))
inp := []byte(data)[:len(data):len(data)]
FuzzDeserialize(inp)
FuzzParseLog(inp)
}
}

0 comments on commit 7c7ded6

Please sign in to comment.