From 3bcdec13657598f6a6163c7ddecff58c2d3a2a71 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 16 Dec 2020 08:57:04 +0100 Subject: 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. --- pkg/tool/flags_fuzz.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pkg/tool/flags_fuzz.go (limited to 'pkg/tool/flags_fuzz.go') 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 +} -- cgit mrf-deployment