diff --git a/route/address.go b/route/address.go index 5443d67223..f42d723b36 100644 --- a/route/address.go +++ b/route/address.go @@ -172,18 +172,31 @@ 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 || l < 4 { return nil, errInvalidAddr } a := &Inet4Addr{} - copy(a.IP[:], b[4:8]) + n := 8 + if l < 8 { + n = l + } + copy(a.IP[:], b[4:n]) return a, nil case syscall.AF_INET6: - if len(b) < sizeofSockaddrInet6 { + l := int(b[0]) + if len(b) < l || l < 8 { return nil, errInvalidAddr } - a := &Inet6Addr{ZoneID: int(nativeEndian.Uint32(b[24:28]))} - copy(a.IP[:], b[8:24]) + n := 24 + if l < 24 { + n = l + } + a := &Inet6Addr{} + if n >= 28 { + a.ZoneID = int(nativeEndian.Uint32(b[24:28])) + } + copy(a.IP[:], b[8:n]) if a.IP[0] == 0xfe && a.IP[1]&0xc0 == 0x80 || a.IP[0] == 0xff && (a.IP[1]&0x0f == 0x01 || a.IP[1]&0x0f == 0x02) { // KAME based IPv6 protocol stack usually // embeds the interface index in the