mirror of https://github.com/jackc/pgx.git
Initial fuzz testing and fix
Initial fuzz testing of pgproto3 found a panicpull/1281/head
parent
2da0a11c52
commit
9d0f27bc4b
pgproto3
testdata/fuzz/FuzzFrontend
|
@ -223,7 +223,13 @@ func (f *Frontend) Receive() (BackendMessage, error) {
|
|||
}
|
||||
|
||||
f.msgType = header[0]
|
||||
f.bodyLen = int(binary.BigEndian.Uint32(header[1:])) - 4
|
||||
|
||||
msgLength := int(binary.BigEndian.Uint32(header[1:]))
|
||||
if msgLength < 4 {
|
||||
return nil, fmt.Errorf("invalid message length: %d", msgLength)
|
||||
}
|
||||
|
||||
f.bodyLen = msgLength - 4
|
||||
f.partialMsg = true
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package pgproto3_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgproto3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func FuzzFrontend(f *testing.F) {
|
||||
testcases := [][]byte{
|
||||
{'Z', 0, 0, 0, 5},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
f.Add(tc)
|
||||
}
|
||||
f.Fuzz(func(t *testing.T, encodedMsg []byte) {
|
||||
r := &bytes.Buffer{}
|
||||
w := &bytes.Buffer{}
|
||||
fe := pgproto3.NewFrontend(r, w)
|
||||
|
||||
_, err := r.Write(encodedMsg)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Not checking anything other than no panic.
|
||||
fe.Receive()
|
||||
})
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
go test fuzz v1
|
||||
[]byte("0\x00\x00\x00\x02")
|
Loading…
Reference in New Issue