diff --git a/Makefile b/Makefile index 7dc71bc..efc1838 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,10 @@ fmt: ## Run go fmt against code tests: ## Run all tests and requires a running rabbitmq-server. Use GO_TEST_FLAGS to add extra flags to go test go test -race -v -tags integration $(GO_TEST_FLAGS) +.PHONY: fuzzing +fuzzing: ## Run fuzzing tests + go test -fuzz=FuzzReadFrame . + .PHONY: tests-docker tests-docker: rabbitmq-server RABBITMQ_RABBITMQCTL_PATH="DOCKER:$(CONTAINER_NAME)" go test -race -v -tags integration $(GO_TEST_FLAGS) diff --git a/fuzz.go b/fuzz.go deleted file mode 100644 index c9f03ea..0000000 --- a/fuzz.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2021 VMware, Inc. or its affiliates. All Rights Reserved. -// Copyright (c) 2012-2021, Sean Treadway, SoundCloud Ltd. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build gofuzz -// +build gofuzz - -package amqp091 - -import "bytes" - -func Fuzz(data []byte) int { - r := reader{bytes.NewReader(data)} - frame, err := r.ReadFrame() - if err != nil { - if frame != nil { - panic("frame is not nil") - } - return 0 - } - return 1 -} diff --git a/read_test.go b/read_test.go index fb44cb1..110a243 100644 --- a/read_test.go +++ b/read_test.go @@ -6,6 +6,7 @@ package amqp091 import ( + "bytes" "strings" "testing" ) @@ -29,3 +30,15 @@ func TestGoFuzzCrashers(t *testing.T) { } } } + +func FuzzReadFrame(f *testing.F) { + + f.Add([]byte("\b000000")) + f.Add([]byte("\x02\x16\x10�[��\t\xbdui�" + "\x10\x01\x00\xff\xbf\xef\xbfサn\x99\x00\x10r")) + f.Add([]byte("\x0300\x00\x00\x00\x040000")) + + f.Fuzz(func(t *testing.T, input_data []byte) { + r := reader{bytes.NewReader(input_data)} + _, _ = r.ReadFrame() + }) +}