public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] debuginfod: Always request servname from getnameinfo for conninfo.
Date: Mon,  9 May 2022 23:10:44 +0200	[thread overview]
Message-ID: <20220509211044.54967-1-mark@klomp.org> (raw)

When getting the connection info getnameinfo is called getting the
hostname and servname except when the sockaddr is a pure ipv6
address. In that last case only hostname is requested. Since servname
is stack allocated and not initialized it might contain garbage which
is then put in the log. Just always request both hostname and servname
with NI_NUMERICHOST | NI_NUMERICSERV.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 debuginfod/ChangeLog      |  4 ++++
 debuginfod/debuginfod.cxx | 15 ++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 983fd44a..257ac39f 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,7 @@
+2022-05-09  Mark Wielaard  <mark@klomp.org>
+
+	* debuginfod.cxx (conninfo): Always provide servname to getnameinfo.
+
 2022-05-09  Mark Wielaard  <mark@klomp.org>
 
 	* debuginfod-client.c (debuginfod_query_server): Add
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 4aaf41c0..b664b74e 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -1060,8 +1060,10 @@ conninfo (struct MHD_Connection * conn)
   struct sockaddr *so = u ? u->client_addr : 0;
 
   if (so && so->sa_family == AF_INET) {
-    sts = getnameinfo (so, sizeof (struct sockaddr_in), hostname, sizeof (hostname), servname,
-                       sizeof (servname), NI_NUMERICHOST | NI_NUMERICSERV);
+    sts = getnameinfo (so, sizeof (struct sockaddr_in),
+                       hostname, sizeof (hostname),
+                       servname, sizeof (servname),
+                       NI_NUMERICHOST | NI_NUMERICSERV);
   } else if (so && so->sa_family == AF_INET6) {
     struct sockaddr_in6* addr6 = (struct sockaddr_in6*) so;
     if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
@@ -1071,11 +1073,14 @@ conninfo (struct MHD_Connection * conn)
       addr4.sin_port = addr6->sin6_port;
       memcpy (&addr4.sin_addr.s_addr, addr6->sin6_addr.s6_addr+12, sizeof(addr4.sin_addr.s_addr));
       sts = getnameinfo ((struct sockaddr*) &addr4, sizeof (addr4),
-                         hostname, sizeof (hostname), servname, sizeof (servname),
+                         hostname, sizeof (hostname),
+                         servname, sizeof (servname),
                          NI_NUMERICHOST | NI_NUMERICSERV);
     } else {
-      sts = getnameinfo (so, sizeof (struct sockaddr_in6), hostname, sizeof (hostname), NULL, 0,
-                         NI_NUMERICHOST);
+      sts = getnameinfo (so, sizeof (struct sockaddr_in6),
+                         hostname, sizeof (hostname),
+                         servname, sizeof (servname),
+                         NI_NUMERICHOST | NI_NUMERICSERV);
     }
   }
   
-- 
2.30.2


             reply	other threads:[~2022-05-09 21:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09 21:10 Mark Wielaard [this message]
2022-05-14 22:15 ` Mark Wielaard

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=20220509211044.54967-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).