aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/tool/flags_fuzz.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-12-16 08:57:04 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-12-25 10:12:41 +0100
commit3bcdec13657598f6a6163c7ddecff58c2d3a2a71 (patch)
tree3ff27333aeecc6eb7be333bc4407647792968ff1 /pkg/tool/flags_fuzz.go
parent80795712865ca86bb21ebb9841598ccbcbd375c9 (diff)
pkg/tool: add package
Package tool contains various helper utilitites useful for implementation of command line tools. Currently it contains Fail/Failf functions that we commonly use and new support for optional command line flags.
Diffstat (limited to 'pkg/tool/flags_fuzz.go')
-rw-r--r--pkg/tool/flags_fuzz.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/tool/flags_fuzz.go b/pkg/tool/flags_fuzz.go
new file mode 100644
index 000000000..3f0bb010a
--- /dev/null
+++ b/pkg/tool/flags_fuzz.go
@@ -0,0 +1,28 @@
+// Copyright 2020 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package tool
+
+import (
+ "reflect"
+ "strings"
+)
+
+func FuzzParseFlags(data []byte) int {
+ flags, err := deserializeFlags(string(data))
+ if err != nil {
+ return 0
+ }
+ value := serializeFlags(flags)
+ if strings.IndexByte(value, ' ') != -1 {
+ panic("flags contain space")
+ }
+ flags1, err := deserializeFlags(value)
+ if err != nil {
+ panic(err)
+ }
+ if !reflect.DeepEqual(flags, flags1) {
+ panic("changed")
+ }
+ return 1
+}