nl_linux: align message length before parsing.

Signed-off-by: Nadia Pinaeva <n.m.pinaeva@gmail.com>
This commit is contained in:
Nadia Pinaeva 2024-04-25 09:28:44 +02:00 committed by Alessandro Boch
parent 578e95cc31
commit 856e190dd7
1 changed files with 3 additions and 2 deletions

View File

@ -804,8 +804,9 @@ func (s *NetlinkSocket) Receive() ([]syscall.NetlinkMessage, *unix.SockaddrNetli
if nr < unix.NLMSG_HDRLEN { if nr < unix.NLMSG_HDRLEN {
return nil, nil, fmt.Errorf("Got short response from netlink") return nil, nil, fmt.Errorf("Got short response from netlink")
} }
rb2 := make([]byte, nr) msgLen := nlmAlignOf(nr)
copy(rb2, rb[:nr]) rb2 := make([]byte, msgLen)
copy(rb2, rb[:msgLen])
nl, err := syscall.ParseNetlinkMessage(rb2) nl, err := syscall.ParseNetlinkMessage(rb2)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err