mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Do not create empty slices in Bind.Decode
This commit is contained in:
parent
dbcfa46d8e
commit
3080d0ee4d
@ -209,9 +209,7 @@ func PgxInitSteps() []Step {
|
|||||||
}),
|
}),
|
||||||
SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'}),
|
SendMessage(&pgproto3.ReadyForQuery{TxStatus: 'I'}),
|
||||||
ExpectMessage(&pgproto3.Bind{
|
ExpectMessage(&pgproto3.Bind{
|
||||||
ParameterFormatCodes: []int16{},
|
ResultFormatCodes: []int16{1, 1},
|
||||||
Parameters: [][]byte{},
|
|
||||||
ResultFormatCodes: []int16{1, 1},
|
|
||||||
}),
|
}),
|
||||||
ExpectMessage(&pgproto3.Execute{}),
|
ExpectMessage(&pgproto3.Execute{}),
|
||||||
ExpectMessage(&pgproto3.Sync{}),
|
ExpectMessage(&pgproto3.Sync{}),
|
||||||
|
@ -18,6 +18,8 @@ type Bind struct {
|
|||||||
func (*Bind) Frontend() {}
|
func (*Bind) Frontend() {}
|
||||||
|
|
||||||
func (dst *Bind) Decode(src []byte) error {
|
func (dst *Bind) Decode(src []byte) error {
|
||||||
|
*dst = Bind{}
|
||||||
|
|
||||||
idx := bytes.IndexByte(src, 0)
|
idx := bytes.IndexByte(src, 0)
|
||||||
if idx < 0 {
|
if idx < 0 {
|
||||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||||
@ -38,14 +40,16 @@ func (dst *Bind) Decode(src []byte) error {
|
|||||||
parameterFormatCodeCount := int(binary.BigEndian.Uint16(src[rp:]))
|
parameterFormatCodeCount := int(binary.BigEndian.Uint16(src[rp:]))
|
||||||
rp += 2
|
rp += 2
|
||||||
|
|
||||||
dst.ParameterFormatCodes = make([]int16, parameterFormatCodeCount)
|
if parameterFormatCodeCount > 0 {
|
||||||
|
dst.ParameterFormatCodes = make([]int16, parameterFormatCodeCount)
|
||||||
|
|
||||||
if len(src[rp:]) < len(dst.ParameterFormatCodes)*2 {
|
if len(src[rp:]) < len(dst.ParameterFormatCodes)*2 {
|
||||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||||
}
|
}
|
||||||
for i := 0; i < parameterFormatCodeCount; i++ {
|
for i := 0; i < parameterFormatCodeCount; i++ {
|
||||||
dst.ParameterFormatCodes[i] = int16(binary.BigEndian.Uint16(src[rp:]))
|
dst.ParameterFormatCodes[i] = int16(binary.BigEndian.Uint16(src[rp:]))
|
||||||
rp += 2
|
rp += 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(src[rp:]) < 2 {
|
if len(src[rp:]) < 2 {
|
||||||
@ -54,27 +58,29 @@ func (dst *Bind) Decode(src []byte) error {
|
|||||||
parameterCount := int(binary.BigEndian.Uint16(src[rp:]))
|
parameterCount := int(binary.BigEndian.Uint16(src[rp:]))
|
||||||
rp += 2
|
rp += 2
|
||||||
|
|
||||||
dst.Parameters = make([][]byte, parameterCount)
|
if parameterCount > 0 {
|
||||||
|
dst.Parameters = make([][]byte, parameterCount)
|
||||||
|
|
||||||
for i := 0; i < parameterCount; i++ {
|
for i := 0; i < parameterCount; i++ {
|
||||||
if len(src[rp:]) < 4 {
|
if len(src[rp:]) < 4 {
|
||||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||||
|
}
|
||||||
|
|
||||||
|
msgSize := int(int32(binary.BigEndian.Uint32(src[rp:])))
|
||||||
|
rp += 4
|
||||||
|
|
||||||
|
// null
|
||||||
|
if msgSize == -1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(src[rp:]) < msgSize {
|
||||||
|
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.Parameters[i] = src[rp : rp+msgSize]
|
||||||
|
rp += msgSize
|
||||||
}
|
}
|
||||||
|
|
||||||
msgSize := int(int32(binary.BigEndian.Uint32(src[rp:])))
|
|
||||||
rp += 4
|
|
||||||
|
|
||||||
// null
|
|
||||||
if msgSize == -1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(src[rp:]) < msgSize {
|
|
||||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
|
||||||
}
|
|
||||||
|
|
||||||
dst.Parameters[i] = src[rp : rp+msgSize]
|
|
||||||
rp += msgSize
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(src[rp:]) < 2 {
|
if len(src[rp:]) < 2 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user