aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pkg/kcidb/client.go18
-rw-r--r--tools/syz-kcidb/kcidb.go45
2 files changed, 54 insertions, 9 deletions
diff --git a/pkg/kcidb/client.go b/pkg/kcidb/client.go
index bba811c7e..091cbbefb 100644
--- a/pkg/kcidb/client.go
+++ b/pkg/kcidb/client.go
@@ -84,6 +84,24 @@ func (c *Client) Publish(bug *dashapi.BugReport) error {
return err
}
+func (c *Client) PublishToFile(bug *dashapi.BugReport, filename string) error {
+ target := targets.List[bug.OS][bug.VMArch]
+ if target == nil {
+ return fmt.Errorf("unsupported OS/arch %v/%v", bug.OS, bug.VMArch)
+ }
+ data, err := json.MarshalIndent(c.convert(target, bug), "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal kcidb json: %w", err)
+ }
+ if err := kcidbValidate(data); err != nil {
+ return err
+ }
+ if err := os.WriteFile(filename, data, 0644); err != nil {
+ return fmt.Errorf("failed to write kcidb json to file: %w", err)
+ }
+ return nil
+}
+
var Validate bool
func kcidbValidate(data []byte) error {
diff --git a/tools/syz-kcidb/kcidb.go b/tools/syz-kcidb/kcidb.go
index 8d1255cce..429059060 100644
--- a/tools/syz-kcidb/kcidb.go
+++ b/tools/syz-kcidb/kcidb.go
@@ -5,7 +5,9 @@ package main
import (
"context"
+ "encoding/json"
"flag"
+ "os"
"github.com/google/syzkaller/dashboard/dashapi"
"github.com/google/syzkaller/pkg/kcidb"
@@ -25,16 +27,33 @@ func main() {
flagDashAddr = flag.String("addr", "", "dashboard address")
flagDashKey = flag.String("key", "", "dashboard API key")
flagBug = flag.String("bug", "", "bug ID to upload to KCIDB")
+ flagInput = flag.String("input", "", "input JSON file with bug report")
+ flagOutput = flag.String("output", "", "output JSON file for KCIDB data")
)
flag.Parse()
- dash, err := dashapi.New(*flagDashClient, *flagDashAddr, *flagDashKey)
- if err != nil {
- tool.Fail(err)
- }
- bug, err := dash.LoadBug(*flagBug)
- if err != nil {
- tool.Fail(err)
+ var bug *dashapi.BugReport
+
+ // If input file is specified, read from file instead of calling API
+ if *flagInput != "" {
+ data, err := os.ReadFile(*flagInput)
+ if err != nil {
+ tool.Fail(err)
+ }
+ bug = &dashapi.BugReport{}
+ if err := json.Unmarshal(data, bug); err != nil {
+ tool.Fail(err)
+ }
+ } else {
+ // Original behavior: fetch from dashboard API
+ dash, err := dashapi.New(*flagDashClient, *flagDashAddr, *flagDashKey)
+ if err != nil {
+ tool.Fail(err)
+ }
+ bug, err = dash.LoadBug(*flagBug)
+ if err != nil {
+ tool.Fail(err)
+ }
}
kcidb.Validate = true
@@ -44,7 +63,15 @@ func main() {
}
defer client.Close()
- if err := client.Publish(bug); err != nil {
- tool.Fail(err)
+ // If output file is specified, write to file instead of submitting.
+ if *flagOutput != "" {
+ if err := client.PublishToFile(bug, *flagOutput); err != nil {
+ tool.Fail(err)
+ }
+ } else {
+ // Original behavior: submit to REST API
+ if err := client.Publish(bug); err != nil {
+ tool.Fail(err)
+ }
}
}