prog: fix out-of-bounds access

ParseLog can access data out-of-bounds.
Fix that and fix regression fuzz tests to catch this.
This commit is contained in:
Dmitry Vyukov 2019-07-30 19:33:02 +02:00
parent 3b37734422
commit 7c7ded697e
3 changed files with 6 additions and 4 deletions

View File

@ -372,6 +372,6 @@ func TestFuzz(t *testing.T) {
"cleaned vnod\re", "cleaned vnod\re",
"kernel\r:", "kernel\r:",
} { } {
Fuzz([]byte(data)) Fuzz([]byte(data)[:len(data):len(data)])
} }
} }

View File

@ -26,7 +26,7 @@ func (target *Target) ParseLog(data []byte) []*LogEntry {
for pos := 0; pos < len(data); { for pos := 0; pos < len(data); {
nl := bytes.IndexByte(data[pos:], '\n') nl := bytes.IndexByte(data[pos:], '\n')
if nl == -1 { if nl == -1 {
nl = len(data) nl = len(data) - 1
} else { } else {
nl += pos nl += pos
} }

View File

@ -22,9 +22,11 @@ mutate4()
mutate7() mutate7()
mutate8() mutate8()
`, `,
`E`,
} { } {
t.Logf("test #%v: %q", i, data) t.Logf("test #%v: %q", i, data)
FuzzDeserialize([]byte(data)) inp := []byte(data)[:len(data):len(data)]
FuzzParseLog([]byte(data)) FuzzDeserialize(inp)
FuzzParseLog(inp)
} }
} }