Skip to content

Commit 04c61e3

Browse files
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
1 parent 4542a42 commit 04c61e3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

route/address.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ func (a *Inet6Addr) marshal(b []byte) (int, error) {
172172
func parseInetAddr(af int, b []byte) (Addr, error) {
173173
switch af {
174174
case syscall.AF_INET:
175-
if len(b) < sizeofSockaddrInet {
175+
l := int(b[0])
176+
if len(b) < l {
176177
return nil, errInvalidAddr
177178
}
178179
a := &Inet4Addr{}

0 commit comments

Comments
 (0)