aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-02-21 15:33:28 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-02-21 14:45:26 +0000
commitecc726d47d5bbd5847ed472fb01ca9e87079c6a9 (patch)
tree17c8ee1f073422da0b45a0d53cfdd4ef18680b61 /pkg
parent3af7dd651dc78ce0784bef793d14dd2f72d07138 (diff)
syz-manager: truncate repro logs before reporting
Until we have figured out a way to solve #4495, let's just truncate repro logs before sending them over the dashboard API.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/report/report.go21
-rw-r--r--pkg/report/report_test.go15
2 files changed, 36 insertions, 0 deletions
diff --git a/pkg/report/report.go b/pkg/report/report.go
index 4bf0adead..750ceed14 100644
--- a/pkg/report/report.go
+++ b/pkg/report/report.go
@@ -742,6 +742,27 @@ func replace(where []byte, start, end int, what []byte) []byte {
return where
}
+// Truncate leaves up to `begin` bytes at the beginning of log and
+// up to `end` bytes at the end of the log.
+func Truncate(log []byte, begin, end int) []byte {
+ if begin+end >= len(log) {
+ return log
+ }
+ var b bytes.Buffer
+ b.Write(log[:begin])
+ if begin > 0 {
+ b.WriteString("\n\n")
+ }
+ fmt.Fprintf(&b, "<<cut %d bytes out>>",
+ len(log)-begin-end,
+ )
+ if end > 0 {
+ b.WriteString("\n\n")
+ }
+ b.Write(log[len(log)-end:])
+ return b.Bytes()
+}
+
var (
filenameRe = regexp.MustCompile(`([a-zA-Z0-9_\-\./]*[a-zA-Z0-9_\-]+\.(c|h)):[0-9]+`)
reportFrameRe = regexp.MustCompile(`.* in ([a-zA-Z0-9_]+)`)
diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go
index ba41735a5..934d4552e 100644
--- a/pkg/report/report_test.go
+++ b/pkg/report/report_test.go
@@ -21,6 +21,7 @@ import (
"github.com/google/syzkaller/pkg/report/crash"
"github.com/google/syzkaller/pkg/testutil"
"github.com/google/syzkaller/sys/targets"
+ "github.com/stretchr/testify/assert"
)
var flagUpdate = flag.Bool("update", false, "update test files accordingly to current results")
@@ -430,3 +431,17 @@ func TestFuzz(t *testing.T) {
Fuzz([]byte(data)[:len(data):len(data)])
}
}
+
+func TestTruncate(t *testing.T) {
+ assert.Equal(t, []byte(`01234
+
+<<cut 11 bytes out>>`), Truncate([]byte(`0123456789ABCDEF`), 5, 0))
+ assert.Equal(t, []byte(`<<cut 11 bytes out>>
+
+BCDEF`), Truncate([]byte(`0123456789ABCDEF`), 0, 5))
+ assert.Equal(t, []byte(`0123
+
+<<cut 9 bytes out>>
+
+DEF`), Truncate([]byte(`0123456789ABCDEF`), 4, 3))
+}