From 34ba07ae9fd75dbb9d479a7def5a2a2c8c65a10e Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Nov 07 2022 16:40:06 +0000 Subject: 0.188-3 Resolves: ##2124339 routine rebase of elfutils for rhel 9.2 - Add elfutils-0.188-compile-warnings.patch - Add elfutils-0.188-debuginfod-client-lifetime.patch --- diff --git a/elfutils-0.188-compile-warnings.patch b/elfutils-0.188-compile-warnings.patch new file mode 100644 index 0000000..397583f --- /dev/null +++ b/elfutils-0.188-compile-warnings.patch @@ -0,0 +1,109 @@ +commit 75f2de448f311807e2493f2a37a980e2d872b229 +Author: Mark Wielaard +Date: Thu Nov 3 13:38:45 2022 +0100 + + readelf: Check phdr != NULL or shdr != NULL in handle_dynamic. + + The compiler doesn't know that when use_dynamic_segment is true, + then phdr should/will be non-NULL and otherwise shdr is non-NULL. + Add explicit checks to help the compiler out and in case an error + is made calling the handle_dynamic function. + + Signed-off-by: Mark Wielaard + +diff --git a/src/readelf.c b/src/readelf.c +index 0e0b05c4..e721a209 100644 +--- a/src/readelf.c ++++ b/src/readelf.c +@@ -1828,7 +1828,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr) + size_t dyn_ents; + + /* Get the data of the section. */ +- if (use_dynamic_segment) ++ if (use_dynamic_segment && phdr != NULL) + data = elf_getdata_rawchunk(ebl->elf, phdr->p_offset, + phdr->p_filesz, ELF_T_DYN); + else +@@ -1840,7 +1840,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr) + /* Get the dynamic section entry number */ + dyn_ents = get_dyn_ents (data); + +- if (!use_dynamic_segment) ++ if (!use_dynamic_segment && shdr != NULL) + { + /* Get the section header string table index. */ + if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0)) +@@ -1862,7 +1862,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr) + (int) shdr->sh_link, + elf_strptr (ebl->elf, shstrndx, glink->sh_name)); + } +- else ++ else if (phdr != NULL) + { + printf (ngettext ("\ + \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 "\n", +@@ -1879,7 +1879,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr) + /* if --use-dynamic option is enabled, + use the string table to get the related library info. */ + Elf_Data *strtab_data = NULL; +- if (use_dynamic_segment) ++ if (use_dynamic_segment && phdr != NULL) + { + strtab_data = get_dynscn_strtab(ebl->elf, phdr); + if (strtab_data == NULL) +@@ -1903,7 +1903,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr) + || dyn->d_tag == DT_RPATH + || dyn->d_tag == DT_RUNPATH) + { +- if (! use_dynamic_segment) ++ if (! use_dynamic_segment && shdr != NULL) + name = elf_strptr (ebl->elf, shdr->sh_link, dyn->d_un.d_val); + else if (dyn->d_un.d_val < strtab_data->d_size + && memrchr (strtab_data->d_buf + dyn->d_un.d_val, '\0', + +commit b0a0235771906e3bcd6174c4e3c020b5522b0be5 +Author: Mark Wielaard +Date: Thu Nov 3 13:44:35 2022 +0100 + + libdw: Don't dereference and assign values we are skipping + + We don't use the FDE address encoding byte, so no reason + to read and store it. Just skip past it. + + Signed-off-by: Mark Wielaard + +diff --git a/libdw/dwarf_next_cfi.c b/libdw/dwarf_next_cfi.c +index 23b16885..be08984f 100644 +--- a/libdw/dwarf_next_cfi.c ++++ b/libdw/dwarf_next_cfi.c +@@ -226,7 +226,7 @@ dwarf_next_cfi (const unsigned char e_ident[], + if (sized_augmentation) + { + /* Skip FDE address encoding byte. */ +- encoding = *bytes++; ++ bytes++; + continue; + } + break; + +commit 52a6a3110e019d696284fdd822c2a2f0987dded2 +Author: Mark Wielaard +Date: Thu Nov 3 13:52:32 2022 +0100 + + readelf: Check gelf_getdyn doesn't return NULL + + Signed-off-by: Mark Wielaard + +diff --git a/src/readelf.c b/src/readelf.c +index e721a209..3dafb041 100644 +--- a/src/readelf.c ++++ b/src/readelf.c +@@ -4910,7 +4910,7 @@ get_dynscn_addrs(Elf *elf, GElf_Phdr *phdr, GElf_Addr addrs[i_max]) + GElf_Dyn dyn_mem; + GElf_Dyn *dyn = gelf_getdyn(data, dyn_idx, &dyn_mem); + /* DT_NULL Marks end of dynamic section. */ +- if (dyn->d_tag == DT_NULL) ++ if (dyn == NULL || dyn->d_tag == DT_NULL) + break; + + switch (dyn->d_tag) { diff --git a/elfutils-0.188-debuginfod-client-lifetime.patch b/elfutils-0.188-debuginfod-client-lifetime.patch new file mode 100644 index 0000000..4c8f735 --- /dev/null +++ b/elfutils-0.188-debuginfod-client-lifetime.patch @@ -0,0 +1,171 @@ +commit c424e5f3d24f76e01242d15ba361dc6234706fed +Author: Frank Ch. Eigler +Date: Thu Nov 3 10:07:31 2022 -0400 + + debuginfod.cxx: fix coverity-found use-after-release error + + The debuginfod_client object lifetime needs more careful handling, + made easier with the defer_dtor<> gadget. + + Signed-off-by: Frank Ch. Eigler + +diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx +index f46da6ef..02a11477 100644 +--- a/debuginfod/debuginfod.cxx ++++ b/debuginfod/debuginfod.cxx +@@ -2249,85 +2249,82 @@ handle_buildid (MHD_Connection* conn, + + int fd = -1; + debuginfod_client *client = debuginfod_pool_begin (); +- if (client != NULL) +- { +- debuginfod_set_progressfn (client, & debuginfod_find_progress); ++ if (client == NULL) ++ throw libc_exception(errno, "debuginfod client pool alloc"); ++ defer_dtor client_closer (client, debuginfod_pool_end); ++ ++ debuginfod_set_progressfn (client, & debuginfod_find_progress); + +- if (conn) +- { +- // Transcribe incoming User-Agent: +- string ua = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "User-Agent") ?: ""; +- string ua_complete = string("User-Agent: ") + ua; +- debuginfod_add_http_header (client, ua_complete.c_str()); +- +- // Compute larger XFF:, for avoiding info loss during +- // federation, and for future cyclicity detection. +- string xff = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "X-Forwarded-For") ?: ""; +- if (xff != "") +- xff += string(", "); // comma separated list +- +- unsigned int xff_count = 0; +- for (auto&& i : xff){ +- if (i == ',') xff_count++; +- } ++ if (conn) ++ { ++ // Transcribe incoming User-Agent: ++ string ua = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "User-Agent") ?: ""; ++ string ua_complete = string("User-Agent: ") + ua; ++ debuginfod_add_http_header (client, ua_complete.c_str()); ++ ++ // Compute larger XFF:, for avoiding info loss during ++ // federation, and for future cyclicity detection. ++ string xff = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "X-Forwarded-For") ?: ""; ++ if (xff != "") ++ xff += string(", "); // comma separated list ++ ++ unsigned int xff_count = 0; ++ for (auto&& i : xff){ ++ if (i == ',') xff_count++; ++ } + +- // if X-Forwarded-For: exceeds N hops, +- // do not delegate a local lookup miss to upstream debuginfods. +- if (xff_count >= forwarded_ttl_limit) +- throw reportable_exception(MHD_HTTP_NOT_FOUND, "not found, --forwared-ttl-limit reached \ ++ // if X-Forwarded-For: exceeds N hops, ++ // do not delegate a local lookup miss to upstream debuginfods. ++ if (xff_count >= forwarded_ttl_limit) ++ throw reportable_exception(MHD_HTTP_NOT_FOUND, "not found, --forwared-ttl-limit reached \ + and will not query the upstream servers"); + +- // Compute the client's numeric IP address only - so can't merge with conninfo() +- const union MHD_ConnectionInfo *u = MHD_get_connection_info (conn, +- MHD_CONNECTION_INFO_CLIENT_ADDRESS); +- struct sockaddr *so = u ? u->client_addr : 0; +- char hostname[256] = ""; // RFC1035 +- if (so && so->sa_family == AF_INET) { +- (void) getnameinfo (so, sizeof (struct sockaddr_in), hostname, sizeof (hostname), NULL, 0, +- NI_NUMERICHOST); +- } else if (so && so->sa_family == AF_INET6) { +- struct sockaddr_in6* addr6 = (struct sockaddr_in6*) so; +- if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) { +- struct sockaddr_in addr4; +- memset (&addr4, 0, sizeof(addr4)); +- addr4.sin_family = AF_INET; +- addr4.sin_port = addr6->sin6_port; +- memcpy (&addr4.sin_addr.s_addr, addr6->sin6_addr.s6_addr+12, sizeof(addr4.sin_addr.s_addr)); +- (void) getnameinfo ((struct sockaddr*) &addr4, sizeof (addr4), +- hostname, sizeof (hostname), NULL, 0, +- NI_NUMERICHOST); +- } else { +- (void) getnameinfo (so, sizeof (struct sockaddr_in6), hostname, sizeof (hostname), NULL, 0, +- NI_NUMERICHOST); +- } +- } +- +- string xff_complete = string("X-Forwarded-For: ")+xff+string(hostname); +- debuginfod_add_http_header (client, xff_complete.c_str()); ++ // Compute the client's numeric IP address only - so can't merge with conninfo() ++ const union MHD_ConnectionInfo *u = MHD_get_connection_info (conn, ++ MHD_CONNECTION_INFO_CLIENT_ADDRESS); ++ struct sockaddr *so = u ? u->client_addr : 0; ++ char hostname[256] = ""; // RFC1035 ++ if (so && so->sa_family == AF_INET) { ++ (void) getnameinfo (so, sizeof (struct sockaddr_in), hostname, sizeof (hostname), NULL, 0, ++ NI_NUMERICHOST); ++ } else if (so && so->sa_family == AF_INET6) { ++ struct sockaddr_in6* addr6 = (struct sockaddr_in6*) so; ++ if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) { ++ struct sockaddr_in addr4; ++ memset (&addr4, 0, sizeof(addr4)); ++ addr4.sin_family = AF_INET; ++ addr4.sin_port = addr6->sin6_port; ++ memcpy (&addr4.sin_addr.s_addr, addr6->sin6_addr.s6_addr+12, sizeof(addr4.sin_addr.s_addr)); ++ (void) getnameinfo ((struct sockaddr*) &addr4, sizeof (addr4), ++ hostname, sizeof (hostname), NULL, 0, ++ NI_NUMERICHOST); ++ } else { ++ (void) getnameinfo (so, sizeof (struct sockaddr_in6), hostname, sizeof (hostname), NULL, 0, ++ NI_NUMERICHOST); + } +- +- if (artifacttype == "debuginfo") +- fd = debuginfod_find_debuginfo (client, +- (const unsigned char*) buildid.c_str(), +- 0, NULL); +- else if (artifacttype == "executable") +- fd = debuginfod_find_executable (client, +- (const unsigned char*) buildid.c_str(), +- 0, NULL); +- else if (artifacttype == "source") +- fd = debuginfod_find_source (client, +- (const unsigned char*) buildid.c_str(), +- 0, suffix.c_str(), NULL); +- else if (artifacttype == "section") +- fd = debuginfod_find_section (client, +- (const unsigned char*) buildid.c_str(), +- 0, section.c_str(), NULL); +- ++ } ++ ++ string xff_complete = string("X-Forwarded-For: ")+xff+string(hostname); ++ debuginfod_add_http_header (client, xff_complete.c_str()); + } +- else +- fd = -errno; /* Set by debuginfod_begin. */ +- debuginfod_pool_end (client); +- ++ ++ if (artifacttype == "debuginfo") ++ fd = debuginfod_find_debuginfo (client, ++ (const unsigned char*) buildid.c_str(), ++ 0, NULL); ++ else if (artifacttype == "executable") ++ fd = debuginfod_find_executable (client, ++ (const unsigned char*) buildid.c_str(), ++ 0, NULL); ++ else if (artifacttype == "source") ++ fd = debuginfod_find_source (client, ++ (const unsigned char*) buildid.c_str(), ++ 0, suffix.c_str(), NULL); ++ else if (artifacttype == "section") ++ fd = debuginfod_find_section (client, ++ (const unsigned char*) buildid.c_str(), ++ 0, section.c_str(), NULL); ++ + if (fd >= 0) + { + if (conn != 0) diff --git a/elfutils.spec b/elfutils.spec index a6a1e21..b8bcce0 100644 --- a/elfutils.spec +++ b/elfutils.spec @@ -1,6 +1,6 @@ Name: elfutils Version: 0.188 -%global baserelease 2 +%global baserelease 3 Release: %{baserelease}%{?dist} URL: http://elfutils.org/ %global source_url ftp://sourceware.org/pub/elfutils/%{version}/ @@ -75,6 +75,10 @@ BuildRequires: gettext-devel # Don't export internal function. Patch1: elfutils-0.188-static-extract_section.patch +# Silence some compiler warnings +Patch2: elfutils-0.188-compile-warnings.patch +# The debuginfod_client object lifetime needs more careful handling +Patch3: elfutils-0.188-debuginfod-client-lifetime.patch %description Elfutils is a collection of utilities, including stack (to show @@ -451,6 +455,10 @@ exit 0 %systemd_postun_with_restart debuginfod.service %changelog +* Mon Nov 7 2022 Mark Wielaard - 0.188-3 +- Add elfutils-0.188-compile-warnings.patch +- Add elfutils-0.188-debuginfod-client-lifetime.patch + * Wed Nov 2 2022 Mark Wielaard - 0.188-1 - Upgrade to upsteam elfutils 0.188. - Add elfutils-0.188-static-extract_section.patch.