From: Mark Wielaard Date: Mon, 16 Apr 2018 14:53:56 +0000 (+0200) Subject: Don't read build-id ELF Note in .debug file through phdrs. X-Git-Tag: VALGRIND_3_14_0~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1f543a224eec5afd8cfddea70c1307ed0a20c55;p=thirdparty%2Fvalgrind.git Don't read build-id ELF Note in .debug file through phdrs. Bug #393062 - Reading build-id ELF note through phdrs triggers "debuginfo reader: ensure_valid failed" Skip the phdrs when we have to search the shdrs. In separate .debug files the phdrs might not be valid (they are a copy of the main ELF file) and might trigger assertions when getting image notes based on them. --- diff --git a/NEWS b/NEWS index ce01442d47..95a6196557 100644 --- a/NEWS +++ b/NEWS @@ -104,6 +104,7 @@ where XXXXXX is the bug number as listed below. 393017 Add missing support for xsmaxcdp instruction, bug fixes for xsmincdp, lxssp, stxssp and stxvl instructions. 393023 callgrind_control risks using the wrong vgdb +393062 build-id ELF phdrs read causes "debuginfo reader: ensure_valid failed" 393099 posix_memalign() invalid write if alignment == 0 n-i-bz Fix missing workq_ops operations (macOS) diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c index 70c28e6292..62192f00e1 100644 --- a/coregrind/m_debuginfo/readelf.c +++ b/coregrind/m_debuginfo/readelf.c @@ -1137,7 +1137,11 @@ HChar* find_buildid(DiImage* img, Bool rel_ok, Bool search_shdrs) ElfXX_Ehdr ehdr; ML_(img_get)(&ehdr, img, 0, sizeof(ehdr)); - for (i = 0; i < ehdr.e_phnum; i++) { + /* Skip the phdrs when we have to search the shdrs. In separate + .debug files the phdrs might not be valid (they are a copy of + the main ELF file) and might trigger assertions when getting + image notes based on them. */ + for (i = 0; !search_shdrs && i < ehdr.e_phnum; i++) { ElfXX_Phdr phdr; ML_(img_get)(&phdr, img, ehdr.e_phoff + i * ehdr.e_phentsize, sizeof(phdr));