From f7ecad883569fcd9104d1296a9020cc88cbf4bc7 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 11 Oct 2024 11:38:44 +0200 Subject: tools/syz-reprolist: use official API structs Use the official API structs to avoid duplication, prevent future bugs, and improve consistency (same field names). --- tools/syz-reprolist/external_api.go | 25 ++++++++----------------- tools/syz-reprolist/reprolist.go | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) (limited to 'tools') diff --git a/tools/syz-reprolist/external_api.go b/tools/syz-reprolist/external_api.go index 36fe4ef68..d611691cc 100644 --- a/tools/syz-reprolist/external_api.go +++ b/tools/syz-reprolist/external_api.go @@ -8,14 +8,9 @@ import ( "fmt" "log" "strings" -) -type bugList struct { - Version int - Bugs []struct { - Link string - } -} + "github.com/google/syzkaller/dashboard/api" +) func reproIDFromURL(url string) string { parts := strings.Split(url, "&") @@ -30,7 +25,7 @@ func reproIDFromURL(url string) string { } func getBugList(jsonBugs []byte) ([]string, error) { - var bl bugList + var bl api.BugGroup if err := json.Unmarshal(jsonBugs, &bl); err != nil { return nil, fmt.Errorf("json.Unmarshal: %w", err) } @@ -44,17 +39,13 @@ func getBugList(jsonBugs []byte) ([]string, error) { return res, nil } -type BugDetails struct { - ID string - Crashes []struct { - CReproURL string `json:"c-reproducer"` - } -} - -func makeBugDetails(jsonDetails []byte) (*BugDetails, error) { - var bd BugDetails +func makeBugDetails(jsonDetails []byte) (*api.Bug, error) { + var bd api.Bug if err := json.Unmarshal(jsonDetails, &bd); err != nil { return nil, fmt.Errorf("json.Unmarshal: %w", err) } + if bd.Version != 1 { + return nil, fmt.Errorf("unsupported export version %d", bd.Version) + } return &bd, nil } diff --git a/tools/syz-reprolist/reprolist.go b/tools/syz-reprolist/reprolist.go index 1881c8465..ada367baa 100644 --- a/tools/syz-reprolist/reprolist.go +++ b/tools/syz-reprolist/reprolist.go @@ -311,7 +311,7 @@ func exportNamespace() error { if err != nil { return fmt.Errorf("makeBugDetails: %w", err) } - if cReproURL := bugDetails.Crashes[0].CReproURL; cReproURL != "" { // export max 1 CRepro per bug + if cReproURL := bugDetails.Crashes[0].CReproducer; cReproURL != "" { // export max 1 CRepro per bug reproID := reproIDFromURL(cReproURL) fmt.Printf("[%d](%d/%d)saving c-repro %s for bug %s\n", i, iBug, len(bugURLs), reproID, bugDetails.ID) -- cgit mrf-deployment