diff options
| author | Antonin Décimo <antonin.decimo@gmail.com> | 2019-12-27 22:15:42 +0100 |
|---|---|---|
| committer | Michael Kerrisk <mtk.manpages@gmail.com> | 2019-12-30 19:49:08 +0100 |
| commit | ae10667d4891a592388f8dc63e1b01fed6a1b4bf (patch) | |
| tree | bcd4ec2842dafb38016064b7244a579b59526de9 | |
| parent | 7aec4106be49a7ab35ef102f6473747cdd528c6a (diff) | |
| download | man-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>
| -rw-r--r-- | man7/netlink.7 | 5 |
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; |
