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",
"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); {
nl := bytes.IndexByte(data[pos:], '\n')
if nl == -1 {
nl = len(data)
nl = len(data) - 1
} else {
nl += pos
}

View File

@ -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)
}
}