-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fuzz Uses github.com/dvyukov/go-fuzz; see fuzz.go for instructions Signed-off-by: Mark Pictor <[email protected]> * bounds checks, avoid infinite loop caught with go-fuzz Signed-off-by: Mark Pictor <[email protected]> * fuzz.go copyright Signed-off-by: Mark Pictor <[email protected]> * comment for golint Signed-off-by: Mark Pictor <[email protected]> * update vendor (xz) Signed-off-by: Mark Pictor <[email protected]> * Gopkg.lock Signed-off-by: Mark Pictor <[email protected]> * test using fuzz corpus compress corpus with xz rather than zip because archive is ~1/10th the size Signed-off-by: Mark Pictor <[email protected]> * temp - disable log.Writer() Signed-off-by: Mark Pictor <[email protected]> * remove vendor directory, and Go.lock Signed-off-by: Ronald G. Minnich <[email protected]> * update packaged usage (io/ioutil -> io) Signed-off-by: Ronald G. Minnich <[email protected]> --------- Signed-off-by: Mark Pictor <[email protected]> Signed-off-by: Ronald G. Minnich <[email protected]> Co-authored-by: Mark Pictor <[email protected]>
- Loading branch information
Showing
10 changed files
with
196 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020 the LinuxBoot Authors. All rights reserved | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build gofuzz | ||
|
||
package uefi | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
// go get github.com/dvyukov/go-fuzz/go-fuzz | ||
// go get github.com/dvyukov/go-fuzz/go-fuzz-build | ||
// | ||
// mkdir fuzz | ||
// go-fuzz-build | ||
// go-fuzz -bin uefi-fuzz.zip -workdir fuzz | ||
|
||
type nopWriter struct{} | ||
|
||
func (n *nopWriter) Write(_ []byte) (int, error) { return 0, nil } | ||
|
||
func init() { | ||
//speed up logging | ||
log.SetFlags(0) | ||
log.SetOutput(&nopWriter{}) | ||
} | ||
|
||
const ( | ||
ICK int = iota - 1 | ||
MEH | ||
WOW | ||
) | ||
|
||
// func Parse(buf []byte) (Firmware, error) | ||
func Fuzz(b []byte) int { | ||
//initialize, since something could have changed the polarity | ||
Attributes = ROMAttributes{ErasePolarity: poisonedPolarity} | ||
_, err := Parse(b) | ||
if err == nil { | ||
return MEH | ||
} | ||
return WOW | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2020 the LinuxBoot Authors. All rights reserved | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
|
||
package uefi | ||
|
||
import ( | ||
"archive/tar" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
fp "path/filepath" | ||
"testing" | ||
|
||
"github.com/ulikunitz/xz" | ||
) | ||
|
||
//no-op writer to minimize logging overhead | ||
type nopWriter struct{} | ||
|
||
func (n *nopWriter) Write(_ []byte) (int, error) { return 0, nil } | ||
|
||
// Tests using input from fuzzing runs. Ignores any errors, just checks that the | ||
// inputs do not cause crashes. | ||
// | ||
// To update the input zip after a fuzzing run: | ||
// cd fuzz/corpus | ||
// zip ../../testdata/fuzz_in.zip * | ||
// | ||
// Similarly, the zip can be extracted to use as input corpus. See fuzz.go for | ||
// go-fuzz instructions. | ||
func TestFuzzInputs(t *testing.T) { | ||
// if testing.CoverMode() != "" { | ||
// NOTE - since this test doesn't validate the outputs, coverage from | ||
// it is very low value, essentially inflating the coverage numbers. | ||
// t.Skip("this test will inflate coverage") | ||
// } | ||
|
||
// not available in go < 1.13 | ||
// //restore log behavior at end | ||
// logOut := log.Writer() | ||
// defer log.SetOutput(logOut) | ||
|
||
//no logging output for this test, to increase speed | ||
log.SetOutput(&nopWriter{}) | ||
log.SetFlags(0) | ||
|
||
txz, err := os.Open("testdata/fuzz_in.txz") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer txz.Close() | ||
x, err := xz.NewReader(txz) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
tr := tar.NewReader(x) | ||
for i := 0; ; i++ { | ||
zf, err := tr.Next() | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
t.Error(err) | ||
continue | ||
} | ||
n := fp.Base(zf.Name) | ||
if len(n) > 10 { | ||
n = n[:10] | ||
} else { | ||
t.Logf("short: %s", n) | ||
} | ||
name := fmt.Sprintf("%03d_%s", i, n) | ||
t.Run(name, func(t *testing.T) { | ||
data, err := io.ReadAll(tr) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
//reset polarity before each run, some fuzz files change it | ||
Attributes = ROMAttributes{ErasePolarity: poisonedPolarity} | ||
//ignore any errors - just catch crashes | ||
_, _ = Parse(data) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.