From d7f299088fd1c10868e2e21313dc023ad769407a Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 22 Jan 2023 16:36:22 +1300 Subject: [PATCH] switch to Go's native fuzzing --- .gitignore | 1 - multistream.go | 3 +- multistream_fuzz.go | 28 ------------------ multistream_test.go | 28 ++++++++++++++++++ ...006d5533770e47f781f838970cf1678c3109f9e3-2 | 1 - ...0b2e00d89397c0966a65c9c63871862f5d939ed2-5 | Bin 65 -> 0 bytes ...16c7381993e3c7382f77bed399f36ad2d64951f5-4 | 1 - ...23833462f55515a900e016db2eb943fb474c19f6-2 | 1 - ...29368200289b4418d893fcc1cc269889e0a6bfb0-2 | 1 - ...599f2fcab2882f9e2896e49c68a5955e10dc7122-3 | 1 - ...7a423337dc2c0923e996c50255f0c4a7702581d3-1 | 1 - ...8750ec9ddfe293cd1dc39b4245c21c270f8f52b7-1 | 1 - ...8c377ec00ce8265e2fb3689c098e594f9b2a2c9a-2 | 1 - ...957666b9194bb12689255437cfc23ddb79b9231a-3 | 1 - ...9d8099103966bb2134e94f46e34c312ea366c6b2-1 | 1 - ...a2f77d89c69a5551e3ae0f1e9825e45dfb95ee5d-1 | Bin 3 -> 0 bytes ...b9ecf4a964523aa3508b6f1a001ef5466c067de6-6 | 1 - .../da39a3ee5e6b4b0d3255bfef95601890afd80709 | 0 18 files changed, 29 insertions(+), 42 deletions(-) delete mode 100644 .gitignore delete mode 100644 multistream_fuzz.go delete mode 100644 workdir/corpus/006d5533770e47f781f838970cf1678c3109f9e3-2 delete mode 100644 workdir/corpus/0b2e00d89397c0966a65c9c63871862f5d939ed2-5 delete mode 100644 workdir/corpus/16c7381993e3c7382f77bed399f36ad2d64951f5-4 delete mode 100644 workdir/corpus/23833462f55515a900e016db2eb943fb474c19f6-2 delete mode 100644 workdir/corpus/29368200289b4418d893fcc1cc269889e0a6bfb0-2 delete mode 100644 workdir/corpus/599f2fcab2882f9e2896e49c68a5955e10dc7122-3 delete mode 100644 workdir/corpus/7a423337dc2c0923e996c50255f0c4a7702581d3-1 delete mode 100644 workdir/corpus/8750ec9ddfe293cd1dc39b4245c21c270f8f52b7-1 delete mode 100644 workdir/corpus/8c377ec00ce8265e2fb3689c098e594f9b2a2c9a-2 delete mode 100644 workdir/corpus/957666b9194bb12689255437cfc23ddb79b9231a-3 delete mode 100644 workdir/corpus/9d8099103966bb2134e94f46e34c312ea366c6b2-1 delete mode 100644 workdir/corpus/a2f77d89c69a5551e3ae0f1e9825e45dfb95ee5d-1 delete mode 100644 workdir/corpus/b9ecf4a964523aa3508b6f1a001ef5466c067de6-6 delete mode 100644 workdir/corpus/da39a3ee5e6b4b0d3255bfef95601890afd80709 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 29585fe..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*-fuzz.zip diff --git a/multistream.go b/multistream.go index daca87c..17e1ef7 100644 --- a/multistream.go +++ b/multistream.go @@ -7,10 +7,9 @@ import ( "bufio" "errors" "fmt" + "io" "os" "runtime/debug" - - "io" "sync" "github.com/multiformats/go-varint" diff --git a/multistream_fuzz.go b/multistream_fuzz.go deleted file mode 100644 index 49eb797..0000000 --- a/multistream_fuzz.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build gofuzz - -package multistream - -import "bytes" - -type rwc struct { - *bytes.Reader -} - -func (*rwc) Write(b []byte) (int, error) { - return len(b), nil -} - -func (*rwc) Close() error { - return nil -} - -func Fuzz(b []byte) int { - readStream := bytes.NewReader(b) - input := &rwc{readStream} - - mux := NewMultistreamMuxer() - mux.AddHandler("/a", nil) - mux.AddHandler("/b", nil) - _ = mux.Handle(input) - return 1 -} diff --git a/multistream_test.go b/multistream_test.go index 454e59d..38aa502 100644 --- a/multistream_test.go +++ b/multistream_test.go @@ -7,6 +7,7 @@ import ( "io" "net" "sort" + "strings" "testing" "time" ) @@ -956,3 +957,30 @@ func TestSimopenClientClientFail(t *testing.T) { case <-done: } } + +type rwc struct { + *strings.Reader +} + +func (*rwc) Write(b []byte) (int, error) { + return len(b), nil +} + +func (*rwc) Close() error { + return nil +} + +func FuzzMultistream(f *testing.F) { + f.Add("/libp2p/simultaneous-connect") + f.Add(ProtocolID) + + f.Fuzz(func(t *testing.T, b string) { + readStream := strings.NewReader(b) + input := &rwc{readStream} + + mux := NewMultistreamMuxer[string]() + mux.AddHandler("/a", nil) + mux.AddHandler("/b", nil) + _ = mux.Handle(input) + }) +} diff --git a/workdir/corpus/006d5533770e47f781f838970cf1678c3109f9e3-2 b/workdir/corpus/006d5533770e47f781f838970cf1678c3109f9e3-2 deleted file mode 100644 index 498efe3..0000000 --- a/workdir/corpus/006d5533770e47f781f838970cf1678c3109f9e3-2 +++ /dev/null @@ -1 +0,0 @@ -���� \ No newline at end of file diff --git a/workdir/corpus/0b2e00d89397c0966a65c9c63871862f5d939ed2-5 b/workdir/corpus/0b2e00d89397c0966a65c9c63871862f5d939ed2-5 deleted file mode 100644 index 5e31674237882101655034e8c48faefc6c1f0dfd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 65 scmdnL_x=98@AvNCyMO=ty?ft7Iq!iYATFxZ9