Skip to content

Commit bb9f3ee

Browse files
pkurunnerhao022
authored andcommitted
fix(netdev): validate ieee pfc attr length
Signed-off-by: yeyangyi <2501210756@stu.pku.edu.cn>
1 parent dca5b0d commit bb9f3ee

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

core/metrics/netdev_dcb.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ const (
5353
)
5454

5555
const (
56-
sizeofDcbmsg = 4
57-
sizeofIEEEPfc = 133
56+
sizeofDcbmsg = 4
5857
)
5958

6059
type dcbMsg struct {
@@ -80,8 +79,13 @@ type ieeePfc struct {
8079
Indications [IEEE_8021QAZ_MAX_TCS]uint64 // count of the received pfc frames
8180
}
8281

83-
func deserializeIEEEPfc(b []byte) *ieeePfc {
84-
return (*ieeePfc)(unsafe.Pointer(&b[0:sizeofIEEEPfc][0]))
82+
func deserializeIEEEPfc(b []byte) (*ieeePfc, error) {
83+
size := int(unsafe.Sizeof(ieeePfc{}))
84+
if len(b) < size {
85+
return nil, fmt.Errorf("ieee pfc attr too short: got %d, want at least %d", len(b), size)
86+
}
87+
88+
return (*ieeePfc)(unsafe.Pointer(&b[0])), nil
8589
}
8690

8791
func doDcbRequest(ifname string) ([][]byte, error) {
@@ -107,7 +111,7 @@ func parseAttributes(attrs []syscall.NetlinkRouteAttr) (*ieeePfc, error) {
107111
for _, s := range subattrs {
108112
switch s.Attr.Type {
109113
case DCB_ATTR_IEEE_PFC:
110-
return deserializeIEEEPfc(s.Value), nil
114+
return deserializeIEEEPfc(s.Value)
111115
case DCB_ATTR_IEEE_PEER_PFC:
112116
}
113117
}

0 commit comments

Comments
 (0)