Skip to content

Commit 7c7ded6

Browse files
committed
prog: fix out-of-bounds access
ParseLog can access data out-of-bounds. Fix that and fix regression fuzz tests to catch this.
1 parent 3b37734 commit 7c7ded6

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

pkg/report/report_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,6 @@ func TestFuzz(t *testing.T) {
372372
"cleaned vnod\re",
373373
"kernel\r:",
374374
} {
375-
Fuzz([]byte(data))
375+
Fuzz([]byte(data)[:len(data):len(data)])
376376
}
377377
}

prog/parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (target *Target) ParseLog(data []byte) []*LogEntry {
2626
for pos := 0; pos < len(data); {
2727
nl := bytes.IndexByte(data[pos:], '\n')
2828
if nl == -1 {
29-
nl = len(data)
29+
nl = len(data) - 1
3030
} else {
3131
nl += pos
3232
}

prog/test/fuzz_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ mutate4()
2222
mutate7()
2323
mutate8()
2424
`,
25+
`E`,
2526
} {
2627
t.Logf("test #%v: %q", i, data)
27-
FuzzDeserialize([]byte(data))
28-
FuzzParseLog([]byte(data))
28+
inp := []byte(data)[:len(data):len(data)]
29+
FuzzDeserialize(inp)
30+
FuzzParseLog(inp)
2931
}
3032
}

0 commit comments

Comments
 (0)