Skip to content

Commit c6c2d9d

Browse files
committed
fix: handle l2cap connection param req updates with invalid length data
Signed-off-by: deadprogram <[email protected]>
1 parent b82048c commit c6c2d9d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

l2cap_hci.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ package bluetooth
55
import (
66
"encoding/binary"
77
"encoding/hex"
8+
"errors"
89
)
910

11+
var errInvalidPayloadLength = errors.New("bluetooth: invalid payload length")
12+
1013
const (
1114
connectionParamUpdateRequest = 0x12
1215
connectionParamUpdateResponse = 0x13
@@ -20,6 +23,10 @@ type l2capConnectionParamReqPkt struct {
2023
}
2124

2225
func (l *l2capConnectionParamReqPkt) Write(buf []byte) (int, error) {
26+
if len(buf) < 8 {
27+
return 0, errInvalidPayloadLength
28+
}
29+
2330
l.minInterval = binary.LittleEndian.Uint16(buf[0:])
2431
l.maxInterval = binary.LittleEndian.Uint16(buf[2:])
2532
l.latency = binary.LittleEndian.Uint16(buf[4:])
@@ -29,6 +36,10 @@ func (l *l2capConnectionParamReqPkt) Write(buf []byte) (int, error) {
2936
}
3037

3138
func (l *l2capConnectionParamReqPkt) Read(p []byte) (int, error) {
39+
if len(p) < 8 {
40+
return 0, errInvalidPayloadLength
41+
}
42+
3243
binary.LittleEndian.PutUint16(p[0:], l.minInterval)
3344
binary.LittleEndian.PutUint16(p[2:], l.maxInterval)
3445
binary.LittleEndian.PutUint16(p[4:], l.latency)

0 commit comments

Comments
 (0)