Skip to content

Commit

Permalink
Potential fix for #44740
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hurricanehrndz committed Aug 29, 2024
1 parent 4542a42 commit 04c61e3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion route/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 04c61e3

Please sign in to comment.