binutils/binutils-readelf-no-sections.patch
yahmad 5e53841477 - Fic configuration of s390x binutils so that it does not include support for extraneous targets. (#2139143)
- Fix readelf's decoding of files with no sections.  (#2131609)
- Stop potential infinite loop in the binutils DWARF parser.  (#2122675)

NOTE: Getting back in sync. Previous commit was done by mistake.
(commit f3e2e5419db81abb950d61ee197d1afcc910a0cc)
2022-11-17 16:06:53 +01:00

30 lines
1.0 KiB
Diff

--- binutils.orig/binutils/readelf.c 2022-10-03 13:20:42.707527855 +0100
+++ binutils-2.39/binutils/readelf.c 2022-10-03 13:21:25.785436781 +0100
@@ -6357,6 +6357,13 @@ get_32bit_section_headers (Filedata * fi
/* PR binutils/17531: Cope with unexpected section header sizes. */
if (size == 0 || num == 0)
return false;
+
+ /* The section header cannot be at the start of the file - that is
+ where the ELF file header is located. A file with absolutely no
+ sections in it will use a shoff of 0. */
+ if (filedata->file_header.e_shoff == 0)
+ return false;
+
if (size < sizeof * shdrs)
{
if (! probe)
@@ -6421,6 +6428,12 @@ get_64bit_section_headers (Filedata * fi
if (size == 0 || num == 0)
return false;
+ /* The section header cannot be at the start of the file - that is
+ where the ELF file header is located. A file with absolutely no
+ sections in it will use a shoff of 0. */
+ if (filedata->file_header.e_shoff == 0)
+ return false;
+
if (size < sizeof * shdrs)
{
if (! probe)