From 44508f85a0b2f4f42ea89d477d575b1bd5a71b60 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Mon, 9 Oct 2023 18:04:21 +0200 Subject: tools/syz-fmt: support --dry-run mode Introduce the --dry-run mode to enable syz-fmt use for description validation only. --- tools/syz-fmt/syz-fmt.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/syz-fmt/syz-fmt.go b/tools/syz-fmt/syz-fmt.go index 2fe918951..e1966aef3 100644 --- a/tools/syz-fmt/syz-fmt.go +++ b/tools/syz-fmt/syz-fmt.go @@ -6,6 +6,7 @@ package main import ( "bytes" + "flag" "fmt" "os" "path/filepath" @@ -13,15 +14,21 @@ import ( "github.com/google/syzkaller/pkg/ast" "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/pkg/tool" "github.com/google/syzkaller/sys/targets" ) +var ( + flagDryRun = flag.Bool("dry-run", false, "do not patch the files, just check if they are well formatted") +) + func main() { - if len(os.Args) < 2 { + defer tool.Init()() + args := flag.Args() + if len(args) < 1 { fmt.Fprintf(os.Stderr, "usage: syz-fmt files... or dirs... or all\n") os.Exit(1) } - args := os.Args[1:] if len(args) == 1 && args[0] == "all" { args = nil for os := range targets.List { @@ -67,6 +74,11 @@ func processFile(file string, mode os.FileMode) { if bytes.Equal(data, formatted) { return } + if *flagDryRun { + fmt.Fprintf(os.Stderr, "%v is not well-formatted, please run syz-fmt against it\n", file) + os.Exit(2) + return + } fmt.Printf("reformatting %v\n", file) if err := osutil.Rename(file, file+"~"); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) -- cgit mrf-deployment