Bug fix from audit.
This commit is contained in:
@@ -41,6 +41,8 @@ func (p Ping) Marshal(buf []byte) []byte {
|
|||||||
|
|
||||||
buf[0] = version
|
buf[0] = version
|
||||||
binary.BigEndian.PutUint64(buf[1:9], uint64(p.PingTS))
|
binary.BigEndian.PutUint64(buf[1:9], uint64(p.PingTS))
|
||||||
|
|
||||||
|
// SrcV4.
|
||||||
if p.SrcV4.IsValid() {
|
if p.SrcV4.IsValid() {
|
||||||
a4 := p.SrcV4.Addr().As4()
|
a4 := p.SrcV4.Addr().As4()
|
||||||
copy(buf[9:13], a4[:])
|
copy(buf[9:13], a4[:])
|
||||||
@@ -48,9 +50,13 @@ func (p Ping) Marshal(buf []byte) []byte {
|
|||||||
} else {
|
} else {
|
||||||
clear(buf[9:15])
|
clear(buf[9:15])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SrcV6.
|
||||||
a16 := p.SrcV6.Addr().As16()
|
a16 := p.SrcV6.Addr().As16()
|
||||||
copy(buf[15:31], a16[:])
|
copy(buf[15:31], a16[:])
|
||||||
binary.BigEndian.PutUint16(buf[31:33], p.SrcV6.Port())
|
binary.BigEndian.PutUint16(buf[31:33], p.SrcV6.Port())
|
||||||
|
|
||||||
|
// Dst.
|
||||||
a16 = p.Dst.Addr().As16()
|
a16 = p.Dst.Addr().As16()
|
||||||
copy(buf[33:49], a16[:])
|
copy(buf[33:49], a16[:])
|
||||||
binary.BigEndian.PutUint16(buf[49:51], p.Dst.Port())
|
binary.BigEndian.PutUint16(buf[49:51], p.Dst.Port())
|
||||||
@@ -72,7 +78,7 @@ func Unmarshal(buf [Size]byte) (Ping, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addr = netip.AddrFrom16([16]byte(buf[15:31])).Unmap()
|
addr = netip.AddrFrom16([16]byte(buf[15:31])).Unmap()
|
||||||
if addr.IsUnspecified() && addr.Is6() {
|
if !addr.IsUnspecified() && addr.Is6() {
|
||||||
p.SrcV6 = netip.AddrPortFrom(addr, binary.BigEndian.Uint16(buf[31:33]))
|
p.SrcV6 = netip.AddrPortFrom(addr, binary.BigEndian.Uint16(buf[31:33]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user