linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sock_diag.7: Fix recvmsg() usage in the example
@ 2021-01-16 18:45 Pali Rohár
  2021-01-17 16:08 ` Alejandro Colomar (man-pages)
  0 siblings, 1 reply; 4+ messages in thread
From: Pali Rohár @ 2021-01-16 18:45 UTC (permalink / raw)
  To: linux-man, Alejandro Colomar, Michael Kerrisk

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>
---
 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 91ccf3ac5..191e6ac49 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.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] sock_diag.7: Fix recvmsg() usage in the example
@ 2021-01-24 15:10 Alejandro Colomar
  2021-01-25  7:02 ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2021-01-24 15:10 UTC (permalink / raw)
  To: mtk.manpages; +Cc: linux-man, Pali Rohár, Alejandro Colomar

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-25  7:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-16 18:45 [PATCH] sock_diag.7: Fix recvmsg() usage in the example Pali Rohár
2021-01-17 16:08 ` Alejandro Colomar (man-pages)
2021-01-24 15:10 Alejandro Colomar
2021-01-25  7:02 ` Michael Kerrisk (man-pages)

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).