Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Go fuzz tests #679

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ vet:
test:
MONGODB_TEST_CXN=mongodb://db:27017 go test -v -cover `go list ./... | grep -v quickfix/gen`

fuzz:
go test -fuzztime 600s -fuzz=FuzzParser .
go test -fuzztime 600s -fuzz=FuzzParseMessage .

linters-install:
@golangci-lint --version >/dev/null 2>&1 || { \
echo "installing linting tools..."; \
Expand Down
24 changes: 24 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,27 @@ func checkFieldString(s *MessageSuite, fields FieldMap, tag int, expected string
s.NoError(err)
s.Equal(expected, toCheck)
}

func FuzzParseMessage(f *testing.F) {

rawMsg0 := "8=FIX.4.29=10435=D34=249=TW52=20140515-19:49:56.65956=ISLD11=10021=140=154=155=TSLA60=00010101-00:00:00.00010=039"
rawMsg1 := "8=FIX.4.29=37235=n34=25512369=148152=20200522-07:05:33.75649=CME50=G56=OAEAAAN57=TRADE_CAPTURE143=US,IL212=261213=<RTRF>8=FIX.4.29=22535=BZ34=6549369=651852=20200522-07:05:33.74649=CME50=G56=9Q5000N57=DUMMY143=US,IL11=ACP159013113373460=20200522-07:05:33.734533=0893=Y1028=Y1300=991369=99612:325081373=31374=91375=15979=159013113373461769710=167</RTRF>10=245\""
rawMsg2 := "8=FIX.4.29=10435=D34=249=TW52=20140515-19:49:56.65956=ISLD11=10021=140=154=155=TSLA60=00010101-00:00:00.00010=039"
rawMsg3 := "8=FIX.4.29=12635=D34=249=TW52=20140515-19:49:56.65956=ISLD10030=CUST11=10021=140=154=155=TSLA60=00010101-00:00:00.0005050=HELLO10=039"
rawMsg4 := "8=FIX.4.09=8135=D11=id21=338=10040=154=155=MSFT34=249=TW52=20140521-22:07:0956=ISLD10=250"

f.Add(rawMsg0)
f.Add(rawMsg1)
f.Add(rawMsg2)
f.Add(rawMsg3)
f.Add(rawMsg4)

f.Fuzz(func(_ *testing.T, input string) {
if len(input) < 8 {
return
}

msg := NewMessage()
_ = ParseMessage(msg, bytes.NewBufferString(input))
})
}
22 changes: 22 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,25 @@ func (s *ParserSuite) TestReadMessageGrowBuffer() {
s.Equal(tc.expectedBufferLen, len(s.parser.buffer))
}
}

func FuzzParser(f *testing.F) {

stream0 := "8=FIXT.1.19=11135=D34=449=TW52=20140511-23:10:3456=ISLD11=ID21=340=154=155=INTC60=20140511-23:10:3410=2348=FIXT.1.19=9535=D34=549=TW52=20140511-23:10:3456=ISLD11=ID21=340=154=155=INTC60=20140511-23:10:3410=198"
stream1 := "8=\x019=\x01"
stream2 := "8=\x019=9300000000000000000\x01"
stream3 := "hello8=FIX.4.09=5blah10=1038=FIX.4.09=4foo10=103"

f.Add(stream0)
f.Add(stream1)
f.Add(stream2)
f.Add(stream3)

f.Fuzz(func(_ *testing.T, input string) {
if len(input) < 8 {
return
}

parser := newParser(strings.NewReader(input))
_, _ = parser.ReadMessage()
})
}
Loading