diff options
author | Mark Wielaard <mark@klomp.org> | 2022-05-08 10:59:52 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2022-05-15 00:05:07 +0200 |
commit | 4b5c8d1380715123f1b832fca932722e8c6651d2 (patch) | |
tree | ff9ec2103b6e852f44d242678c4ffa6315350f30 /debuginfod | |
parent | 0f2c8af3ba82ac54acc63ab7cb068578a6c0d96e (diff) | |
download | elfutils-4b5c8d1380715123f1b832fca932722e8c6651d2.tar.gz |
debuginfod: Always request servname from getnameinfo for conninfo.
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>
Diffstat (limited to 'debuginfod')
-rw-r--r-- | debuginfod/ChangeLog | 4 | ||||
-rw-r--r-- | debuginfod/debuginfod.cxx | 15 |
2 files changed, 14 insertions, 5 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 505ff2e7..39f7d731 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,5 +1,9 @@ 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 curl_easy_setopt_ck macro, use it for all curl_easy_setopt calls. diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index e7ea356c..13980ced 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); } } |