public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] debuginfod: Always request servname from getnameinfo for conninfo.
@ 2022-05-09 21:10 Mark Wielaard
  2022-05-14 22:15 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2022-05-09 21:10 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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


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

* Re: [PATCH] debuginfod: Always request servname from getnameinfo for conninfo.
  2022-05-09 21:10 [PATCH] debuginfod: Always request servname from getnameinfo for conninfo Mark Wielaard
@ 2022-05-14 22:15 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2022-05-14 22:15 UTC (permalink / raw)
  To: elfutils-devel

Hi,

On Mon, May 09, 2022 at 11:10:44PM +0200, Mark Wielaard wrote:
> 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.

Pushed.

Cheers,

Mark

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

end of thread, other threads:[~2022-05-14 22:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 21:10 [PATCH] debuginfod: Always request servname from getnameinfo for conninfo Mark Wielaard
2022-05-14 22:15 ` Mark Wielaard

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