|
|
ea5461 |
commit c424e5f3d24f76e01242d15ba361dc6234706fed
|
|
|
ea5461 |
Author: Frank Ch. Eigler <fche@redhat.com>
|
|
|
ea5461 |
Date: Thu Nov 3 10:07:31 2022 -0400
|
|
|
ea5461 |
|
|
|
ea5461 |
debuginfod.cxx: fix coverity-found use-after-release error
|
|
|
ea5461 |
|
|
|
ea5461 |
The debuginfod_client object lifetime needs more careful handling,
|
|
|
ea5461 |
made easier with the defer_dtor<> gadget.
|
|
|
ea5461 |
|
|
|
ea5461 |
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
|
|
|
ea5461 |
|
|
|
ea5461 |
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
|
|
|
ea5461 |
index f46da6ef..02a11477 100644
|
|
|
ea5461 |
--- a/debuginfod/debuginfod.cxx
|
|
|
ea5461 |
+++ b/debuginfod/debuginfod.cxx
|
|
|
ea5461 |
@@ -2249,85 +2249,82 @@ handle_buildid (MHD_Connection* conn,
|
|
|
ea5461 |
|
|
|
ea5461 |
int fd = -1;
|
|
|
ea5461 |
debuginfod_client *client = debuginfod_pool_begin ();
|
|
|
ea5461 |
- if (client != NULL)
|
|
|
ea5461 |
- {
|
|
|
ea5461 |
- debuginfod_set_progressfn (client, & debuginfod_find_progress);
|
|
|
ea5461 |
+ if (client == NULL)
|
|
|
ea5461 |
+ throw libc_exception(errno, "debuginfod client pool alloc");
|
|
|
ea5461 |
+ defer_dtor<debuginfod_client*,void> client_closer (client, debuginfod_pool_end);
|
|
|
ea5461 |
+
|
|
|
ea5461 |
+ debuginfod_set_progressfn (client, & debuginfod_find_progress);
|
|
|
ea5461 |
|
|
|
ea5461 |
- if (conn)
|
|
|
ea5461 |
- {
|
|
|
ea5461 |
- // Transcribe incoming User-Agent:
|
|
|
ea5461 |
- string ua = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "User-Agent") ?: "";
|
|
|
ea5461 |
- string ua_complete = string("User-Agent: ") + ua;
|
|
|
ea5461 |
- debuginfod_add_http_header (client, ua_complete.c_str());
|
|
|
ea5461 |
-
|
|
|
ea5461 |
- // Compute larger XFF:, for avoiding info loss during
|
|
|
ea5461 |
- // federation, and for future cyclicity detection.
|
|
|
ea5461 |
- string xff = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "X-Forwarded-For") ?: "";
|
|
|
ea5461 |
- if (xff != "")
|
|
|
ea5461 |
- xff += string(", "); // comma separated list
|
|
|
ea5461 |
-
|
|
|
ea5461 |
- unsigned int xff_count = 0;
|
|
|
ea5461 |
- for (auto&& i : xff){
|
|
|
ea5461 |
- if (i == ',') xff_count++;
|
|
|
ea5461 |
- }
|
|
|
ea5461 |
+ if (conn)
|
|
|
ea5461 |
+ {
|
|
|
ea5461 |
+ // Transcribe incoming User-Agent:
|
|
|
ea5461 |
+ string ua = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "User-Agent") ?: "";
|
|
|
ea5461 |
+ string ua_complete = string("User-Agent: ") + ua;
|
|
|
ea5461 |
+ debuginfod_add_http_header (client, ua_complete.c_str());
|
|
|
ea5461 |
+
|
|
|
ea5461 |
+ // Compute larger XFF:, for avoiding info loss during
|
|
|
ea5461 |
+ // federation, and for future cyclicity detection.
|
|
|
ea5461 |
+ string xff = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "X-Forwarded-For") ?: "";
|
|
|
ea5461 |
+ if (xff != "")
|
|
|
ea5461 |
+ xff += string(", "); // comma separated list
|
|
|
ea5461 |
+
|
|
|
ea5461 |
+ unsigned int xff_count = 0;
|
|
|
ea5461 |
+ for (auto&& i : xff){
|
|
|
ea5461 |
+ if (i == ',') xff_count++;
|
|
|
ea5461 |
+ }
|
|
|
ea5461 |
|
|
|
ea5461 |
- // if X-Forwarded-For: exceeds N hops,
|
|
|
ea5461 |
- // do not delegate a local lookup miss to upstream debuginfods.
|
|
|
ea5461 |
- if (xff_count >= forwarded_ttl_limit)
|
|
|
ea5461 |
- throw reportable_exception(MHD_HTTP_NOT_FOUND, "not found, --forwared-ttl-limit reached \
|
|
|
ea5461 |
+ // if X-Forwarded-For: exceeds N hops,
|
|
|
ea5461 |
+ // do not delegate a local lookup miss to upstream debuginfods.
|
|
|
ea5461 |
+ if (xff_count >= forwarded_ttl_limit)
|
|
|
ea5461 |
+ throw reportable_exception(MHD_HTTP_NOT_FOUND, "not found, --forwared-ttl-limit reached \
|
|
|
ea5461 |
and will not query the upstream servers");
|
|
|
ea5461 |
|
|
|
ea5461 |
- // Compute the client's numeric IP address only - so can't merge with conninfo()
|
|
|
ea5461 |
- const union MHD_ConnectionInfo *u = MHD_get_connection_info (conn,
|
|
|
ea5461 |
- MHD_CONNECTION_INFO_CLIENT_ADDRESS);
|
|
|
ea5461 |
- struct sockaddr *so = u ? u->client_addr : 0;
|
|
|
ea5461 |
- char hostname[256] = ""; // RFC1035
|
|
|
ea5461 |
- if (so && so->sa_family == AF_INET) {
|
|
|
ea5461 |
- (void) getnameinfo (so, sizeof (struct sockaddr_in), hostname, sizeof (hostname), NULL, 0,
|
|
|
ea5461 |
- NI_NUMERICHOST);
|
|
|
ea5461 |
- } else if (so && so->sa_family == AF_INET6) {
|
|
|
ea5461 |
- struct sockaddr_in6* addr6 = (struct sockaddr_in6*) so;
|
|
|
ea5461 |
- if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
|
|
|
ea5461 |
- struct sockaddr_in addr4;
|
|
|
ea5461 |
- memset (&addr4, 0, sizeof(addr4));
|
|
|
ea5461 |
- addr4.sin_family = AF_INET;
|
|
|
ea5461 |
- addr4.sin_port = addr6->sin6_port;
|
|
|
ea5461 |
- memcpy (&addr4.sin_addr.s_addr, addr6->sin6_addr.s6_addr+12, sizeof(addr4.sin_addr.s_addr));
|
|
|
ea5461 |
- (void) getnameinfo ((struct sockaddr*) &addr4, sizeof (addr4),
|
|
|
ea5461 |
- hostname, sizeof (hostname), NULL, 0,
|
|
|
ea5461 |
- NI_NUMERICHOST);
|
|
|
ea5461 |
- } else {
|
|
|
ea5461 |
- (void) getnameinfo (so, sizeof (struct sockaddr_in6), hostname, sizeof (hostname), NULL, 0,
|
|
|
ea5461 |
- NI_NUMERICHOST);
|
|
|
ea5461 |
- }
|
|
|
ea5461 |
- }
|
|
|
ea5461 |
-
|
|
|
ea5461 |
- string xff_complete = string("X-Forwarded-For: ")+xff+string(hostname);
|
|
|
ea5461 |
- debuginfod_add_http_header (client, xff_complete.c_str());
|
|
|
ea5461 |
+ // Compute the client's numeric IP address only - so can't merge with conninfo()
|
|
|
ea5461 |
+ const union MHD_ConnectionInfo *u = MHD_get_connection_info (conn,
|
|
|
ea5461 |
+ MHD_CONNECTION_INFO_CLIENT_ADDRESS);
|
|
|
ea5461 |
+ struct sockaddr *so = u ? u->client_addr : 0;
|
|
|
ea5461 |
+ char hostname[256] = ""; // RFC1035
|
|
|
ea5461 |
+ if (so && so->sa_family == AF_INET) {
|
|
|
ea5461 |
+ (void) getnameinfo (so, sizeof (struct sockaddr_in), hostname, sizeof (hostname), NULL, 0,
|
|
|
ea5461 |
+ NI_NUMERICHOST);
|
|
|
ea5461 |
+ } else if (so && so->sa_family == AF_INET6) {
|
|
|
ea5461 |
+ struct sockaddr_in6* addr6 = (struct sockaddr_in6*) so;
|
|
|
ea5461 |
+ if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
|
|
|
ea5461 |
+ struct sockaddr_in addr4;
|
|
|
ea5461 |
+ memset (&addr4, 0, sizeof(addr4));
|
|
|
ea5461 |
+ addr4.sin_family = AF_INET;
|
|
|
ea5461 |
+ addr4.sin_port = addr6->sin6_port;
|
|
|
ea5461 |
+ memcpy (&addr4.sin_addr.s_addr, addr6->sin6_addr.s6_addr+12, sizeof(addr4.sin_addr.s_addr));
|
|
|
ea5461 |
+ (void) getnameinfo ((struct sockaddr*) &addr4, sizeof (addr4),
|
|
|
ea5461 |
+ hostname, sizeof (hostname), NULL, 0,
|
|
|
ea5461 |
+ NI_NUMERICHOST);
|
|
|
ea5461 |
+ } else {
|
|
|
ea5461 |
+ (void) getnameinfo (so, sizeof (struct sockaddr_in6), hostname, sizeof (hostname), NULL, 0,
|
|
|
ea5461 |
+ NI_NUMERICHOST);
|
|
|
ea5461 |
}
|
|
|
ea5461 |
-
|
|
|
ea5461 |
- if (artifacttype == "debuginfo")
|
|
|
ea5461 |
- fd = debuginfod_find_debuginfo (client,
|
|
|
ea5461 |
- (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
- 0, NULL);
|
|
|
ea5461 |
- else if (artifacttype == "executable")
|
|
|
ea5461 |
- fd = debuginfod_find_executable (client,
|
|
|
ea5461 |
- (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
- 0, NULL);
|
|
|
ea5461 |
- else if (artifacttype == "source")
|
|
|
ea5461 |
- fd = debuginfod_find_source (client,
|
|
|
ea5461 |
- (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
- 0, suffix.c_str(), NULL);
|
|
|
ea5461 |
- else if (artifacttype == "section")
|
|
|
ea5461 |
- fd = debuginfod_find_section (client,
|
|
|
ea5461 |
- (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
- 0, section.c_str(), NULL);
|
|
|
ea5461 |
-
|
|
|
ea5461 |
+ }
|
|
|
ea5461 |
+
|
|
|
ea5461 |
+ string xff_complete = string("X-Forwarded-For: ")+xff+string(hostname);
|
|
|
ea5461 |
+ debuginfod_add_http_header (client, xff_complete.c_str());
|
|
|
ea5461 |
}
|
|
|
ea5461 |
- else
|
|
|
ea5461 |
- fd = -errno; /* Set by debuginfod_begin. */
|
|
|
ea5461 |
- debuginfod_pool_end (client);
|
|
|
ea5461 |
-
|
|
|
ea5461 |
+
|
|
|
ea5461 |
+ if (artifacttype == "debuginfo")
|
|
|
ea5461 |
+ fd = debuginfod_find_debuginfo (client,
|
|
|
ea5461 |
+ (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
+ 0, NULL);
|
|
|
ea5461 |
+ else if (artifacttype == "executable")
|
|
|
ea5461 |
+ fd = debuginfod_find_executable (client,
|
|
|
ea5461 |
+ (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
+ 0, NULL);
|
|
|
ea5461 |
+ else if (artifacttype == "source")
|
|
|
ea5461 |
+ fd = debuginfod_find_source (client,
|
|
|
ea5461 |
+ (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
+ 0, suffix.c_str(), NULL);
|
|
|
ea5461 |
+ else if (artifacttype == "section")
|
|
|
ea5461 |
+ fd = debuginfod_find_section (client,
|
|
|
ea5461 |
+ (const unsigned char*) buildid.c_str(),
|
|
|
ea5461 |
+ 0, section.c_str(), NULL);
|
|
|
ea5461 |
+
|
|
|
ea5461 |
if (fd >= 0)
|
|
|
ea5461 |
{
|
|
|
ea5461 |
if (conn != 0)
|