1
0
mirror of https://github.com/osrg/gobgp.git synced 2024-05-11 05:55:10 +00:00

[Fuzzing] fuzzing support for oss-fuzz

Signed-off-by: Arjun Singh <ajsinghyadav00@gmail.com>
This commit is contained in:
Arjun Singh
2023-09-19 20:39:25 +05:30
parent 9692041417
commit 60bcfc20f2
7 changed files with 93 additions and 0 deletions

View File

@ -69,3 +69,18 @@ This will produce a version number of
## Layout
The GoBGP project adopts [Standard Go Project Layout](https://github.com/golang-standards/project-layout).
## Fuzzing
Run [Go Fuzzing](https://go.dev/security/fuzz)
```bash
go test -fuzz=FuzzParseRTR $PWD/pkg/packet/rtr
go test -fuzz=FuzzParseBMPMessage $PWD/pkg/packet/bmp
go test -fuzz=FuzzParseBGPMessage $PWD/pkg/packet/bgp
go test -fuzz=FuzzParseLargeCommunity $PWD/pkg/packet/bgp
go test -fuzz=FuzzParseFlowSpecComponents $PWD/pkg/packet/bgp
go test -fuzz=FuzzMRT $PWD/pkg/packet/mrt
go test -fuzz=FuzzZapi $PWD/internal/pkg/zebra
```

View File

@ -1120,3 +1120,28 @@ func Test_vrfLabelBody(t *testing.T) {
assert.Equal(bufIn, bufOut)
}
}
func FuzzZapi(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
if len(data) < 16 {
return
}
for v := MinZapiVer; v <= MaxZapiVer; v++ {
ZAPIHeaderSize := int(HeaderSize(v))
hd := &Header{}
err := hd.decodeFromBytes(data[:ZAPIHeaderSize])
if err != nil {
return
}
software := NewSoftware(v, "")
parseMessage(hd, data[:ZAPIHeaderSize], software)
}
})
}

View File

@ -3715,3 +3715,17 @@ func Test_BGPOpenDecodeCapabilities(t *testing.T) {
assert.Equal(t, tuples[0].RouteFamily, RF_IPv4_UC)
assert.Equal(t, tuples[0].Mode, BGP_ADD_PATH_SEND)
}
func FuzzParseBGPMessage(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
ParseBGPMessage(data)
})
}
func FuzzParseFlowSpecComponents(f *testing.F) {
f.Fuzz(func(t *testing.T, data string) {
ParseFlowSpecComponents(RF_FS_IPv4_UC, data)
})
}

View File

@ -421,3 +421,10 @@ func TestValidateLargeCommunities(t *testing.T) {
assert.Nil(err)
assert.True(len(a.Values) == 2)
}
func FuzzParseLargeCommunity(f *testing.F) {
f.Fuzz(func(t *testing.T, data string) {
ParseLargeCommunity(data)
})
}

View File

@ -158,3 +158,10 @@ func Test_RouteMonitoringUnknownType(t *testing.T) {
_, err := ParseBMPMessage(data)
require.NoError(t, err)
}
func FuzzParseBMPMessage(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
ParseBMPMessage(data)
})
}

View File

@ -300,3 +300,21 @@ func TestMrtSplit(t *testing.T) {
t.Logf("scanner scanned %d serialized keepalives from the buffer", numread)
assert.Equal(t, numwrite, numread)
}
func FuzzMRT(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
if len(data) < 16 {
return
}
hdr := &MRTHeader{}
err := hdr.DecodeFromBytes(data[:MRT_COMMON_HEADER_LEN])
if err != nil {
return
}
ParseMRTBody(hdr, data[MRT_COMMON_HEADER_LEN:])
})
}

View File

@ -115,3 +115,10 @@ func Test_RTRErrorReport(t *testing.T) {
// when it has both "erroneous PDU" and "Arbitrary Text"
verifyRTRMessage(t, NewRTRErrorReport(CORRUPT_DATA, errPDU, errText2))
}
func FuzzParseRTR(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
ParseRTR(data)
})
}