• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 syzkaller project authors. All rights reserved.
2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4package report
5
6import (
7	"bytes"
8	"regexp"
9)
10
11type freebsd struct {
12	kernelSrc string
13	kernelObj string
14	ignores   []*regexp.Regexp
15}
16
17func ctorFreebsd(kernelSrc, kernelObj string, ignores []*regexp.Regexp) (Reporter, []string, error) {
18	ctx := &freebsd{
19		kernelSrc: kernelSrc,
20		kernelObj: kernelObj,
21		ignores:   ignores,
22	}
23	return ctx, nil, nil
24}
25
26func (ctx *freebsd) ContainsCrash(output []byte) bool {
27	return containsCrash(output, freebsdOopses, ctx.ignores)
28}
29
30func (ctx *freebsd) Parse(output []byte) *Report {
31	rep := &Report{
32		Output: output,
33	}
34	var oops *oops
35	for pos := 0; pos < len(output); {
36		next := bytes.IndexByte(output[pos:], '\n')
37		if next != -1 {
38			next += pos
39		} else {
40			next = len(output)
41		}
42		for _, oops1 := range freebsdOopses {
43			match := matchOops(output[pos:next], oops1, ctx.ignores)
44			if match == -1 {
45				continue
46			}
47			if oops == nil {
48				oops = oops1
49				rep.StartPos = pos
50				rep.Title = string(output[pos+match : next])
51			}
52			rep.EndPos = next
53		}
54		// Console output is indistinguishable from fuzzer output,
55		// so we just collect everything after the oops.
56		if oops != nil {
57			lineEnd := next
58			if lineEnd != 0 && output[lineEnd-1] == '\r' {
59				lineEnd--
60			}
61			rep.Report = append(rep.Report, output[pos:lineEnd]...)
62			rep.Report = append(rep.Report, '\n')
63		}
64		pos = next + 1
65	}
66	if oops == nil {
67		return nil
68	}
69	title, corrupted, _ := extractDescription(output[rep.StartPos:], oops, freebsdStackParams)
70	rep.Title = title
71	rep.Corrupted = corrupted != ""
72	rep.CorruptedReason = corrupted
73	return rep
74}
75
76func (ctx *freebsd) Symbolize(rep *Report) error {
77	return nil
78}
79
80var freebsdStackParams = &stackParams{}
81
82var freebsdOopses = []*oops{
83	{
84		[]byte("Fatal trap"),
85		[]oopsFormat{
86			{
87				title: compile("Fatal trap (.+?)\\r?\\n(?:.*\\n)+?" +
88					"KDB: stack backtrace:\\r?\\n" +
89					"(?:#[0-9]+ {{ADDR}} at (?:kdb_backtrace|vpanic|panic|trap_fatal|" +
90					"trap_pfault|trap|calltrap|m_copydata|__rw_wlock_hard)" +
91					"\\+{{ADDR}}\\r?\\n)*#[0-9]+ {{ADDR}} at {{FUNC}}{{ADDR}}"),
92				fmt: "Fatal trap %[1]v in %[2]v",
93			},
94		},
95		[]*regexp.Regexp{},
96	},
97	{
98		[]byte("panic:"),
99		[]oopsFormat{
100			{
101				title: compile("panic: ffs_write: type {{ADDR}} [0-9]+ \\([0-9]+,[0-9]+\\)"),
102				fmt:   "panic: ffs_write: type ADDR X (Y,Z)",
103			},
104		},
105		[]*regexp.Regexp{},
106	},
107}
108