From 04c61e3fc1432a9f2c2a3f49deba5c4a4744dfb8 Mon Sep 17 00:00:00 2001 From: Carlos Hernandez Date: Thu, 29 Aug 2024 11:50:59 -0600 Subject: [PATCH] Potential fix for #44740 sizeofSockaddrInet is 16, but first byte of sockaddr specifies the size of the address. 16 works for most cases, except with Netmasks addresses, on Darwin where only the significant bits are in the msg. i.e. 06 02 00 00 ff ff The above byte sequence is for a sockaddr that is 6 bytes long representing an ipv4 for address that is 255.255.0.0. Confirmed by using `route monitor`. sources: https://github.com/apple/darwin-xnu/blob/main/bsd/net/route.h https://github.com/apple/darwin-xnu/blob/main/bsd/sys/socket.h#L603 --- route/address.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/route/address.go b/route/address.go index 5443d67223..9aa2ee113d 100644 --- a/route/address.go +++ b/route/address.go @@ -172,7 +172,8 @@ func (a *Inet6Addr) marshal(b []byte) (int, error) { func parseInetAddr(af int, b []byte) (Addr, error) { switch af { case syscall.AF_INET: - if len(b) < sizeofSockaddrInet { + l := int(b[0]) + if len(b) < l { return nil, errInvalidAddr } a := &Inet4Addr{}