]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elfcompress: Fix off-by-one sanity check
authorMark Wielaard <mark@klomp.org>
Mon, 18 May 2026 18:14:44 +0000 (20:14 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 21 May 2026 16:48:26 +0000 (18:48 +0200)
The elf ndx should not be bigger than, or equal to shnum. This really
should never trigger unless elf_ndx and/or elf_getshdrnum is buggy.

* src/elfcompress.c (process_file): Check ndx >= shnum.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/elfcompress.c

index 630eb54da1c09adfd9b22fa6764613bda6446f12..25ebd1be5c623943fd3d50c297f78e3e4c33ed2a 100644 (file)
@@ -483,7 +483,7 @@ process_file (const char *fname)
   while ((scn = elf_nextscn (elf, scn)) != NULL)
     {
       size_t ndx = elf_ndxscn (scn);
-      if (ndx > shnum)
+      if (ndx >= shnum)
        {
          error (0, 0, "Unexpected section number %zd, expected only %zd",
                 ndx, shnum);