Skip to content

Commit 91305db

Browse files
nuclearcata-nogikh
authored andcommitted
tools/syz-kcidb: add -input and -output flags for testing
Add -input and -output flags to syz-kcidb to allow for faster and easier testing of KCIDB submissions. With these flags, it's possible to use a local JSON file as input for a bug report and to save the resulting KCIDB submission locally. This removes the need for communication with the dashboard and KCIDB, which simplifies testing and development. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent fd07048 commit 91305db

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

pkg/kcidb/client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ func (c *Client) Publish(bug *dashapi.BugReport) error {
8484
return err
8585
}
8686

87+
func (c *Client) PublishToFile(bug *dashapi.BugReport, filename string) error {
88+
target := targets.List[bug.OS][bug.VMArch]
89+
if target == nil {
90+
return fmt.Errorf("unsupported OS/arch %v/%v", bug.OS, bug.VMArch)
91+
}
92+
data, err := json.MarshalIndent(c.convert(target, bug), "", " ")
93+
if err != nil {
94+
return fmt.Errorf("failed to marshal kcidb json: %w", err)
95+
}
96+
if err := kcidbValidate(data); err != nil {
97+
return err
98+
}
99+
if err := os.WriteFile(filename, data, 0644); err != nil {
100+
return fmt.Errorf("failed to write kcidb json to file: %w", err)
101+
}
102+
return nil
103+
}
104+
87105
var Validate bool
88106

89107
func kcidbValidate(data []byte) error {

tools/syz-kcidb/kcidb.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package main
55

66
import (
77
"context"
8+
"encoding/json"
89
"flag"
10+
"os"
911

1012
"github.com/google/syzkaller/dashboard/dashapi"
1113
"github.com/google/syzkaller/pkg/kcidb"
@@ -25,16 +27,33 @@ func main() {
2527
flagDashAddr = flag.String("addr", "", "dashboard address")
2628
flagDashKey = flag.String("key", "", "dashboard API key")
2729
flagBug = flag.String("bug", "", "bug ID to upload to KCIDB")
30+
flagInput = flag.String("input", "", "input JSON file with bug report")
31+
flagOutput = flag.String("output", "", "output JSON file for KCIDB data")
2832
)
2933
flag.Parse()
3034

31-
dash, err := dashapi.New(*flagDashClient, *flagDashAddr, *flagDashKey)
32-
if err != nil {
33-
tool.Fail(err)
34-
}
35-
bug, err := dash.LoadBug(*flagBug)
36-
if err != nil {
37-
tool.Fail(err)
35+
var bug *dashapi.BugReport
36+
37+
// If input file is specified, read from file instead of calling API
38+
if *flagInput != "" {
39+
data, err := os.ReadFile(*flagInput)
40+
if err != nil {
41+
tool.Fail(err)
42+
}
43+
bug = &dashapi.BugReport{}
44+
if err := json.Unmarshal(data, bug); err != nil {
45+
tool.Fail(err)
46+
}
47+
} else {
48+
// Original behavior: fetch from dashboard API
49+
dash, err := dashapi.New(*flagDashClient, *flagDashAddr, *flagDashKey)
50+
if err != nil {
51+
tool.Fail(err)
52+
}
53+
bug, err = dash.LoadBug(*flagBug)
54+
if err != nil {
55+
tool.Fail(err)
56+
}
3857
}
3958

4059
kcidb.Validate = true
@@ -44,7 +63,15 @@ func main() {
4463
}
4564
defer client.Close()
4665

47-
if err := client.Publish(bug); err != nil {
48-
tool.Fail(err)
66+
// If output file is specified, write to file instead of submitting.
67+
if *flagOutput != "" {
68+
if err := client.PublishToFile(bug, *flagOutput); err != nil {
69+
tool.Fail(err)
70+
}
71+
} else {
72+
// Original behavior: submit to REST API
73+
if err := client.Publish(bug); err != nil {
74+
tool.Fail(err)
75+
}
4976
}
5077
}

0 commit comments

Comments
 (0)