From: Alejandro Colomar <alx.manpages@gmail.com>
To: mtk.manpages@gmail.com
Cc: linux-man@vger.kernel.org, "Pali Rohár" <pali@kernel.org>,
"Alejandro Colomar" <alx.manpages@gmail.com>
Subject: [PATCH] sock_diag.7: Fix recvmsg() usage in the example
Date: Sun, 24 Jan 2021 16:10:39 +0100 [thread overview]
Message-ID: <20210124151035.70536-6-alx.manpages@gmail.com> (raw)
From: Pali Rohár <pali@kernel.org>
The msg_name field for recvmsg() call points to a caller-allocated buffer
nladdr that is used to return the source address of the (netlink) socket.
As recvmsg() does not read this buffer and fills it for a caller, do not
initialize it and instead check its value in the example.
Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---
man7/sock_diag.7 | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/man7/sock_diag.7 b/man7/sock_diag.7
index b732b2571..569106dd6 100644
--- a/man7/sock_diag.7
+++ b/man7/sock_diag.7
@@ -753,9 +753,7 @@ static int
receive_responses(int fd)
{
long buf[8192 / sizeof(long)];
- struct sockaddr_nl nladdr = {
- .nl_family = AF_NETLINK
- };
+ struct sockaddr_nl nladdr;
struct iovec iov = {
.iov_base = buf,
.iov_len = sizeof(buf)
@@ -782,6 +780,11 @@ receive_responses(int fd)
if (ret == 0)
return 0;
+ if (nladdr.nl_family != AF_NETLINK) {
+ fputs("!AF_NETLINK\en", stderr);
+ return \-1;
+ }
+
const struct nlmsghdr *h = (struct nlmsghdr *) buf;
if (!NLMSG_OK(h, ret)) {
--
2.30.0
next reply other threads:[~2021-01-24 15:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-24 15:10 Alejandro Colomar [this message]
2021-01-25 7:02 ` [PATCH] sock_diag.7: Fix recvmsg() usage in the example Michael Kerrisk (man-pages)
-- strict thread matches above, loose matches on Subject: below --
2021-01-16 18:45 Pali Rohár
2021-01-17 16:08 ` Alejandro Colomar (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210124151035.70536-6-alx.manpages@gmail.com \
--to=alx.manpages@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=pali@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).