aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-12-04 11:10:12 +0100
committerDmitry Vyukov <dvyukov@google.com>2017-12-04 11:10:12 +0100
commit84a6637d281c4e14578ff2f64d51ec2e995dd45e (patch)
tree314b09a8324a2a980475573873475b19c3135b34
parent7a5e495bdf4d204bdd696f1e51422661e58ace9c (diff)
pkg/report: add fuzz test
Found 3 bugs already. Update #457
-rw-r--r--pkg/report/fuzz.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/pkg/report/fuzz.go b/pkg/report/fuzz.go
new file mode 100644
index 000000000..b7f5ef2a5
--- /dev/null
+++ b/pkg/report/fuzz.go
@@ -0,0 +1,36 @@
+// Copyright 2017 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+// +build gofuzz
+
+package report
+
+import (
+ "regexp"
+)
+
+var reporter, _ = NewReporter("linux", "", "", nil, []*regexp.Regexp{regexp.MustCompile("foo")})
+
+func FuzzLinux(data []byte) int {
+ containsCrash := reporter.ContainsCrash(data)
+ rep := reporter.Parse(data)
+ if containsCrash != (rep != nil) {
+ panic("ContainsCrash and Parse disagree")
+ }
+ if rep == nil {
+ return 0
+ }
+ if rep.Title == "" {
+ panic("rep.Title == \"\"")
+ }
+ if len(rep.Report) == 0 {
+ panic("len(rep.Report) == 0")
+ }
+ if len(rep.Output) == 0 {
+ panic("len(rep.Output) == 0")
+ }
+ if rep.StartPos >= rep.EndPos {
+ panic("rep.StartPos >= rep.EndPos")
+ }
+ return 1
+}