mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-23 19:28:36 +00:00
netlink: improve edge case when reading out truncated last nlmsg in nb
When there is not enough space for one full message we return it truncated. This enters special block of code that previously may leave empty buffer with offset == datalen in the queue. Avoid that, as dealing later with empty buffers causes more pain than just avoiding them. While here add missing msgrcv increment.
This commit is contained in:
parent
26caf57e0b
commit
e6f4c31460
|
@ -762,11 +762,23 @@ nl_soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio,
|
|||
} else if (len == 0 && uio->uio_resid > 0) {
|
||||
flags |= MSG_TRUNC;
|
||||
partlen = uio->uio_resid;
|
||||
if (!peek) {
|
||||
/* XXX: may leave empty nb */
|
||||
if (peek)
|
||||
goto nospace;
|
||||
datalen += hdr->nlmsg_len;
|
||||
if (nb->offset + hdr->nlmsg_len ==
|
||||
nb->datalen) {
|
||||
/*
|
||||
* Avoid leaving empty nb.
|
||||
* Process last nb normally.
|
||||
* Trust uiomove() to care
|
||||
* about negative uio_resid.
|
||||
*/
|
||||
nb = TAILQ_NEXT(nb, tailq);
|
||||
overflow = 0;
|
||||
partlen = 0;
|
||||
} else
|
||||
nb->offset += hdr->nlmsg_len;
|
||||
datalen += hdr->nlmsg_len;
|
||||
}
|
||||
msgrcv++;
|
||||
} else
|
||||
partlen = 0;
|
||||
goto nospace;
|
||||
|
|
Loading…
Reference in a new issue