aboutsummaryrefslogtreecommitdiffstats
path: root/man7/netlink.7
diff options
context:
space:
mode:
authorAntonin Décimo <antonin.decimo@gmail.com>2019-12-27 22:15:42 +0100
committerMichael Kerrisk <mtk.manpages@gmail.com>2019-12-30 19:49:08 +0100
commitae10667d4891a592388f8dc63e1b01fed6a1b4bf (patch)
treebcd4ec2842dafb38016064b7244a579b59526de9 /man7/netlink.7
parent7aec4106be49a7ab35ef102f6473747cdd528c6a (diff)
downloadman-pages-ae10667d4891a592388f8dc63e1b01fed6a1b4bf.tar.gz
netlink.7: Fix alignment issue in example
PVS-Studio reports that in char buf[8192]; /* ... */ nh = (struct nlmsghdr *) buf, the pointer 'buf' is cast to a more strictly aligned pointer type. This is undefined behaviour. One possible solution to make sure that buf is correctly aligned is to declare buf as an array of struct nlmsghdr. Other solutions include allocating the array on the heap, use an union, or stdalign features. With this patch, the buffer still contains 8192 bytes. This was raised on Stack Overflow: https://stackoverflow.com/questions/57745580/netlink-receive-buffer-alignment Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man7/netlink.7')
-rw-r--r--man7/netlink.75
1 files changed, 3 insertions, 2 deletions
diff --git a/man7/netlink.7 b/man7/netlink.7
index 81d42493e2..853dee67f3 100644
--- a/man7/netlink.7
+++ b/man7/netlink.7
@@ -533,8 +533,9 @@ And the last example is about reading netlink message.
.in +4n
.EX
int len;
-char buf[8192]; /* 8192 to avoid message truncation on
- platforms with page size > 4096 */
+/* 8192 to avoid message truncation on platforms with
+ page size > 4096 */
+struct nlmsghdr buf[8192/sizeof(struct nlmsghdr)];
struct iovec iov = { buf, sizeof(buf) };
struct sockaddr_nl sa;
struct msghdr msg;