udp: make parseRecvCmsg's length check overflow-safe

This commit is contained in:
JackDoan
2026-07-27 15:41:57 -05:00
parent 8006b58758
commit 6fb10c1c1a
2 changed files with 44 additions and 1 deletions
+2 -1
View File
@@ -371,7 +371,8 @@ func parseRecvCmsg(hdr *msghdr, wantGRO, wantECN bool) (gso int, ecn byte) {
for off+unix.SizeofCmsghdr <= len(ctrl) {
ch := (*unix.Cmsghdr)(unsafe.Pointer(&ctrl[off]))
clen := int(ch.Len)
if clen < unix.SizeofCmsghdr || off+clen > len(ctrl) {
// Compare against the remaining bytes rather than off+clen
if clen < unix.SizeofCmsghdr || clen > len(ctrl)-off {
return gso, ecn
}
dataOff := off + unix.CmsgLen(0)