Skip to content

Commit 1292b5c

Browse files
committed
Add fuzz testing
1 parent c7392e8 commit 1292b5c

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ vet:
1616
test:
1717
MONGODB_TEST_CXN=mongodb://db:27017 go test -v -cover `go list ./... | grep -v quickfix/gen`
1818

19+
fuzz:
20+
go test -fuzztime 600s -fuzz=FuzzParser .
21+
go test -fuzztime 600s -fuzz=FuzzParseMessage .
22+
1923
linters-install:
2024
@golangci-lint --version >/dev/null 2>&1 || { \
2125
echo "installing linting tools..."; \

message_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,27 @@ func checkFieldString(s *MessageSuite, fields FieldMap, tag int, expected string
515515
s.NoError(err)
516516
s.Equal(expected, toCheck)
517517
}
518+
519+
func FuzzParseMessage(f *testing.F) {
520+
521+
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"
522+
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\""
523+
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"
524+
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"
525+
rawMsg4 := "8=FIX.4.09=8135=D11=id21=338=10040=154=155=MSFT34=249=TW52=20140521-22:07:0956=ISLD10=250"
526+
527+
f.Add(rawMsg0)
528+
f.Add(rawMsg1)
529+
f.Add(rawMsg2)
530+
f.Add(rawMsg3)
531+
f.Add(rawMsg4)
532+
533+
f.Fuzz(func(_ *testing.T, input string) {
534+
if len(input) < 8 {
535+
return
536+
}
537+
538+
msg := NewMessage()
539+
_ = ParseMessage(msg, bytes.NewBufferString(input))
540+
})
541+
}

parser_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,25 @@ func (s *ParserSuite) TestReadMessageGrowBuffer() {
186186
s.Equal(tc.expectedBufferLen, len(s.parser.buffer))
187187
}
188188
}
189+
190+
func FuzzParser(f *testing.F) {
191+
192+
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"
193+
stream1 := "8=\x019=\x01"
194+
stream2 := "8=\x019=9300000000000000000\x01"
195+
stream3 := "hello8=FIX.4.09=5blah10=1038=FIX.4.09=4foo10=103"
196+
197+
f.Add(stream0)
198+
f.Add(stream1)
199+
f.Add(stream2)
200+
f.Add(stream3)
201+
202+
f.Fuzz(func(_ *testing.T, input string) {
203+
if len(input) < 8 {
204+
return
205+
}
206+
207+
parser := newParser(strings.NewReader(input))
208+
_, _ = parser.ReadMessage()
209+
})
210+
}

0 commit comments

Comments
 (0)