Workaround signedness bugs in system NLMSG_OK reported by -Wsign-compare
Introduce a replacement for NLMSG_OK provided by <linux/netlink.h> since that system macro contains signedness bugs that are not going to be fixed. * netlink.h: Include <stdbool.h>. (is_nlmsg_ok): New static inline function. * socketutils.c (receive_responses): Use it instead of NLMSG_OK. * tests/netlink_inet_diag.c (check_responses): Likewise. * tests/netlink_netlink_diag.c (check_responses): Likewise. * tests/netlink_unix_diag.c (check_responses): Likewise. Closes: https://github.com/strace/strace/issues/79
This commit is contained in:
parent
f708bcfa45
commit
96df4b36f6
@ -29,6 +29,7 @@
|
||||
#ifndef STRACE_NETLINK_H
|
||||
#define STRACE_NETLINK_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
|
||||
@ -63,4 +64,12 @@
|
||||
# define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
|
||||
#endif
|
||||
|
||||
static inline bool
|
||||
is_nlmsg_ok(const struct nlmsghdr *const nlh, const ssize_t len)
|
||||
{
|
||||
return len >= (ssize_t) sizeof(*nlh)
|
||||
&& nlh->nlmsg_len >= sizeof(*nlh)
|
||||
&& (size_t) len >= nlh->nlmsg_len;
|
||||
}
|
||||
|
||||
#endif /* !STRACE_NETLINK_H */
|
||||
|
@ -237,9 +237,9 @@ receive_responses(struct tcb *tcp, const int fd, const unsigned long inode,
|
||||
}
|
||||
|
||||
const struct nlmsghdr *h = &hdr_buf.hdr;
|
||||
if (!NLMSG_OK(h, ret))
|
||||
if (!is_nlmsg_ok(h, ret))
|
||||
return false;
|
||||
for (; NLMSG_OK(h, ret); h = NLMSG_NEXT(h, ret)) {
|
||||
for (; is_nlmsg_ok(h, ret); h = NLMSG_NEXT(h, ret)) {
|
||||
if (h->nlmsg_type != expected_msg_type)
|
||||
return false;
|
||||
const int rc = parser(NLMSG_DATA(h),
|
||||
|
@ -100,8 +100,8 @@ check_responses(const int fd)
|
||||
perror_msg_and_skip("recvmsg");
|
||||
|
||||
struct nlmsghdr *h = &hdr_buf.hdr;
|
||||
if (!NLMSG_OK(h, ret))
|
||||
error_msg_and_skip("!NLMSG_OK");
|
||||
if (!is_nlmsg_ok(h, ret))
|
||||
error_msg_and_skip("!is_nlmsg_ok");
|
||||
if (h->nlmsg_type == NLMSG_ERROR) {
|
||||
const struct nlmsgerr *err = NLMSG_DATA(h);
|
||||
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
|
||||
|
@ -100,8 +100,8 @@ check_responses(const int fd)
|
||||
perror_msg_and_skip("recvmsg");
|
||||
|
||||
struct nlmsghdr *h = &hdr_buf.hdr;
|
||||
if (!NLMSG_OK(h, ret))
|
||||
error_msg_and_skip("!NLMSG_OK");
|
||||
if (!is_nlmsg_ok(h, ret))
|
||||
error_msg_and_skip("!is_nlmsg_ok");
|
||||
if (h->nlmsg_type == NLMSG_ERROR) {
|
||||
const struct nlmsgerr *err = NLMSG_DATA(h);
|
||||
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
|
||||
|
@ -104,8 +104,8 @@ check_responses(const int fd)
|
||||
perror_msg_and_skip("recvmsg");
|
||||
|
||||
struct nlmsghdr *h = &hdr_buf.hdr;
|
||||
if (!NLMSG_OK(h, ret))
|
||||
error_msg_and_skip("!NLMSG_OK");
|
||||
if (!is_nlmsg_ok(h, ret))
|
||||
error_msg_and_skip("!is_nlmsg_ok");
|
||||
if (h->nlmsg_type == NLMSG_ERROR) {
|
||||
const struct nlmsgerr *err = NLMSG_DATA(h);
|
||||
if (h->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user