File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,11 @@ package bluetooth
55import (
66 "encoding/binary"
77 "encoding/hex"
8+ "errors"
89)
910
11+ var errInvalidPayloadLength = errors .New ("bluetooth: invalid payload length" )
12+
1013const (
1114 connectionParamUpdateRequest = 0x12
1215 connectionParamUpdateResponse = 0x13
@@ -20,6 +23,10 @@ type l2capConnectionParamReqPkt struct {
2023}
2124
2225func (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
3138func (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 )
You can’t perform that action at this time.
0 commit comments