diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-06-20 15:44:42 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-06-22 16:40:45 +0200 |
| commit | 3cf0de82e9aaaf2cfdb21f5bc45d444467bbe89b (patch) | |
| tree | b405a97bd902258d1570cd4b31f356046df317aa | |
| parent | 87dda8591f4d5db3cb923373c9aef605f1389b38 (diff) | |
pkg/report: move title sanitization from linux to common code
Stripping dynamic data (addresses, numbers) is required for all OSes.
Move this code from linux to common code.
| -rw-r--r-- | pkg/report/linux.go | 23 | ||||
| -rw-r--r-- | pkg/report/report.go | 54 |
2 files changed, 53 insertions, 24 deletions
diff --git a/pkg/report/linux.go b/pkg/report/linux.go index a2ac1f730..0fc67f80d 100644 --- a/pkg/report/linux.go +++ b/pkg/report/linux.go @@ -243,22 +243,6 @@ func (ctx *linux) Parse(output []byte) *Report { if !rep.Corrupted { rep.Corrupted, rep.corruptedReason = ctx.isCorrupted(title, report, format) } - // Executor PIDs are not interesting. - rep.Title = executorBinRe.ReplaceAllLiteralString(rep.Title, "syz-executor") - // syzkaller binaries are coming from repro. - rep.Title = syzkallerBinRe.ReplaceAllLiteralString(rep.Title, "syzkaller") - // Replace that everything looks like an address with "ADDR", - // addresses in descriptions can't be good regardless of the oops regexps. - rep.Title = addrRe.ReplaceAllString(rep.Title, "${1}ADDR") - // Replace that everything looks like a decimal number with "NUM". - rep.Title = decNumRe.ReplaceAllString(rep.Title, "${1}NUM") - // Replace that everything looks like a file line number with "LINE". - rep.Title = lineNumRe.ReplaceAllLiteralString(rep.Title, ":LINE") - // Replace all raw references to runctions (e.g. "ip6_fragment+0x1052/0x2d80") - // with just function name ("ip6_fragment"). Offsets and sizes are not stable. - rep.Title = funcRe.ReplaceAllString(rep.Title, "$1") - // CPU numbers are not interesting. - rep.Title = cpuRe.ReplaceAllLiteralString(rep.Title, "CPU") return rep } @@ -501,13 +485,6 @@ var ( filenameRe = regexp.MustCompile(`[a-zA-Z0-9_\-\./]*[a-zA-Z0-9_\-]+\.(c|h):[0-9]+`) linuxSymbolizeRe = regexp.MustCompile(`(?:\[\<(?:[0-9a-f]+)\>\])?[ \t]+(?:[0-9]+:)?([a-zA-Z0-9_.]+)\+0x([0-9a-f]+)/0x([0-9a-f]+)`) stackFrameRe = regexp.MustCompile(`^ *(?:\[\<(?:[0-9a-f]+)\>\])?[ \t]+(?:[0-9]+:)?([a-zA-Z0-9_.]+)\+0x([0-9a-f]+)/0x([0-9a-f]+)`) - lineNumRe = regexp.MustCompile(`(:[0-9]+)+`) - addrRe = regexp.MustCompile(`([^a-zA-Z])(?:0x)?[0-9a-f]{8,}`) - decNumRe = regexp.MustCompile(`([^a-zA-Z])[0-9]{5,}`) - funcRe = regexp.MustCompile(`([a-zA-Z][a-zA-Z0-9_.]+)\+0x[0-9a-z]+/0x[0-9a-z]+`) - cpuRe = regexp.MustCompile(`CPU#[0-9]+`) - executorBinRe = regexp.MustCompile(`syz-executor[0-9]+((/|:)[0-9]+)?`) - syzkallerBinRe = regexp.MustCompile(`syzkaller[0-9]+((/|:)[0-9]+)?`) linuxRcuStall = compile("INFO: rcu_(?:preempt|sched|bh) (?:self-)?detected(?: expedited)? stall") linuxRipFrame = compile(`IP: (?:(?:[0-9]+:)?(?:{{PC}} +){0,2}{{FUNC}}|[0-9]+:0x[0-9a-f]+|(?:[0-9]+:)?{{PC}} +\[< *\(null\)>\] +\(null\)|[0-9]+: +\(null\))`) ) diff --git a/pkg/report/report.go b/pkg/report/report.go index a40fedf95..713a3f1fe 100644 --- a/pkg/report/report.go +++ b/pkg/report/report.go @@ -86,10 +86,62 @@ func (wrap reporterWrapper) Parse(output []byte) *Report { if rep == nil { return nil } - rep.Title = sanitizeTitle(rep.Title) + rep.Title = sanitizeTitle(replaceTable(dynamicTitleReplacement, rep.Title)) return rep } +type replacement struct { + match *regexp.Regexp + replacement string +} + +func replaceTable(replacements []replacement, str string) string { + for _, repl := range replacements { + str = repl.match.ReplaceAllString(str, repl.replacement) + } + return str +} + +var dynamicTitleReplacement = []replacement{ + { + // Executor PIDs are not interesting. + regexp.MustCompile(`syz-executor[0-9]+((/|:)[0-9]+)?`), + "syz-executor", + }, + { + // syzkaller binaries are coming from repro. + regexp.MustCompile(`syzkaller[0-9]+((/|:)[0-9]+)?`), + "syzkaller", + }, + { + // Replace that everything looks like an address with "ADDR", + // addresses in descriptions can't be good regardless of the oops regexps. + regexp.MustCompile(`([^a-zA-Z])(?:0x)?[0-9a-f]{6,}`), + "${1}ADDR", + }, + { + // Replace that everything looks like a decimal number with "NUM". + regexp.MustCompile(`([^a-zA-Z])[0-9]{5,}`), + "${1}NUM", + }, + { + // Replace that everything looks like a file line number with "LINE". + regexp.MustCompile(`(:[0-9]+)+`), + ":LINE", + }, + { + // Replace all raw references to runctions (e.g. "ip6_fragment+0x1052/0x2d80") + // with just function name ("ip6_fragment"). Offsets and sizes are not stable. + regexp.MustCompile(`([a-zA-Z][a-zA-Z0-9_.]+)\+0x[0-9a-z]+/0x[0-9a-z]+`), + "${1}", + }, + { + // CPU numbers are not interesting. + regexp.MustCompile(`CPU#[0-9]+`), + "CPU", + }, +} + func sanitizeTitle(title string) string { const maxTitleLen = 120 // Corrupted/intermixed lines can be very long. res := make([]byte, 0, len(title)) |
