diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-11-24 19:33:52 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-11-26 03:28:27 +0100 |
commit | b491454dfc5d8081ef429af1d1a01aed0b83bd25 (patch) | |
tree | 56e309de4a03548c39c4bdef9a3b1e1e5c0b3b9f /src/libsystemd/sd-netlink/netlink-socket.c | |
parent | sd-netlink: allocate read buffer when necessary (diff) | |
download | systemd-b491454dfc5d8081ef429af1d1a01aed0b83bd25.tar.xz systemd-b491454dfc5d8081ef429af1d1a01aed0b83bd25.zip |
sd-netlink: return earlier when received invalid message
Diffstat (limited to 'src/libsystemd/sd-netlink/netlink-socket.c')
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-socket.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 55dc51ab50..5128f8fb4b 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -272,7 +272,12 @@ int socket_read_message(sd_netlink *nl) { return r; len = (size_t) r; - if (NLMSG_OK(nl->rbuffer, len) && nl->rbuffer->nlmsg_flags & NLM_F_MULTI) { + if (!NLMSG_OK(nl->rbuffer, len)) { + log_debug("sd-netlink: received invalid message, discarding %zu bytes of incoming message", len); + return 0; + } + + if (nl->rbuffer->nlmsg_flags & NLM_F_MULTI) { multi_part = true; for (i = 0; i < nl->rqueue_partial_size; i++) @@ -341,7 +346,7 @@ int socket_read_message(sd_netlink *nl) { } if (len > 0) - log_debug("sd-netlink: discarding %zu bytes of incoming message", len); + log_debug("sd-netlink: discarding trailing %zu bytes of incoming message", len); if (!first) return 0; |