From 4744d8ccac58e1b794bf29de93d63b522ff44027 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 28 Oct 2018 15:04:20 +0100 Subject: pkg/report: fix guilty file extraction reportPrefixLen can become wrong after symbolization if we symbolize any lines in the prefix. Adjust reportPrefixLen during symbolization. Automatic testing of this is problematic because we would need to symbolize which requires the object file with debug info. Tested manually with syz-symbolize. --- pkg/report/linux.go | 20 ++++++++++++-------- tools/syz-symbolize/symbolize.go | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/report/linux.go b/pkg/report/linux.go index ff5878370..3e6ebebcf 100644 --- a/pkg/report/linux.go +++ b/pkg/report/linux.go @@ -271,11 +271,9 @@ func (ctx *linux) parseOutput(output []byte) ( func (ctx *linux) Symbolize(rep *Report) error { if ctx.vmlinux != "" { - symbolized, err := ctx.symbolize(rep.Report) - if err != nil { + if err := ctx.symbolize(rep); err != nil { return err } - rep.Report = symbolized } // We still do this even if we did not symbolize, // because tests pass in already symbolized input. @@ -290,19 +288,25 @@ func (ctx *linux) Symbolize(rep *Report) error { return nil } -func (ctx *linux) symbolize(text []byte) ([]byte, error) { +func (ctx *linux) symbolize(rep *Report) error { symb := symbolizer.NewSymbolizer() defer symb.Close() strip := ctx.stripPrefix(symb) var symbolized []byte - s := bufio.NewScanner(bytes.NewReader(text)) + s := bufio.NewScanner(bytes.NewReader(rep.Report)) + prefix := rep.reportPrefixLen for s.Scan() { line := append([]byte{}, s.Bytes()...) line = append(line, '\n') - line = symbolizeLine(symb.Symbolize, ctx.symbols, ctx.vmlinux, strip, line) - symbolized = append(symbolized, line...) + newLine := symbolizeLine(symb.Symbolize, ctx.symbols, ctx.vmlinux, strip, line) + if prefix > len(symbolized) { + prefix += len(newLine) - len(line) + } + symbolized = append(symbolized, newLine...) } - return symbolized, nil + rep.Report = symbolized + rep.reportPrefixLen = prefix + return nil } func (ctx *linux) stripPrefix(symb *symbolizer.Symbolizer) string { diff --git a/tools/syz-symbolize/symbolize.go b/tools/syz-symbolize/symbolize.go index 8ce2f73ff..277e09066 100644 --- a/tools/syz-symbolize/symbolize.go +++ b/tools/syz-symbolize/symbolize.go @@ -52,6 +52,7 @@ func main() { } fmt.Printf("TITLE: %v\n", rep.Title) fmt.Printf("CORRUPTED: %v (%v)\n", rep.Corrupted, rep.CorruptedReason) + fmt.Printf("MAINTAINERS: %v\n", rep.Maintainers) fmt.Printf("\n") os.Stdout.Write(rep.Report) } -- cgit mrf-deployment