Do not create empty slices in Bind.Decode
This commit is contained in:
@@ -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,6 +40,7 @@ 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
|
||||||
|
|
||||||
|
if parameterFormatCodeCount > 0 {
|
||||||
dst.ParameterFormatCodes = make([]int16, parameterFormatCodeCount)
|
dst.ParameterFormatCodes = make([]int16, parameterFormatCodeCount)
|
||||||
|
|
||||||
if len(src[rp:]) < len(dst.ParameterFormatCodes)*2 {
|
if len(src[rp:]) < len(dst.ParameterFormatCodes)*2 {
|
||||||
@@ -47,6 +50,7 @@ func (dst *Bind) Decode(src []byte) error {
|
|||||||
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 {
|
||||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||||
@@ -54,6 +58,7 @@ 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
|
||||||
|
|
||||||
|
if parameterCount > 0 {
|
||||||
dst.Parameters = make([][]byte, parameterCount)
|
dst.Parameters = make([][]byte, parameterCount)
|
||||||
|
|
||||||
for i := 0; i < parameterCount; i++ {
|
for i := 0; i < parameterCount; i++ {
|
||||||
@@ -76,6 +81,7 @@ func (dst *Bind) Decode(src []byte) error {
|
|||||||
dst.Parameters[i] = src[rp : rp+msgSize]
|
dst.Parameters[i] = src[rp : rp+msgSize]
|
||||||
rp += msgSize
|
rp += msgSize
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(src[rp:]) < 2 {
|
if len(src[rp:]) < 2 {
|
||||||
return &invalidMessageFormatErr{messageType: "Bind"}
|
return &invalidMessageFormatErr{messageType: "Bind"}
|
||||||
|
|||||||
Reference in New Issue
Block a user