readelf: Allow .gdb_index const table to be empty

Message ID 20240907220005.447083-1-mark@klomp.org
State Committed
Headers
Series readelf: Allow .gdb_index const table to be empty |

Commit Message

Mark Wielaard Sept. 7, 2024, 10 p.m. UTC
  The .gdb_index const table can be empty, if no symbol table entry
refers to a name or CU. Which technically means the symbol table is
empty or has only zero members.

      * src/readelf.c (print_gdb_index_section): Check const_off is
      not past the end of the data section, it can be at the end.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/readelf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Mark Wielaard Sept. 10, 2024, 4:05 p.m. UTC | #1
Hi,

On Sun, 2024-09-08 at 00:00 +0200, Mark Wielaard wrote:
> The .gdb_index const table can be empty, if no symbol table entry
> refers to a name or CU. Which technically means the symbol table is
> empty or has only zero members.
> 
>       * src/readelf.c (print_gdb_index_section): Check const_off is
>       not past the end of the data section, it can be at the end.

Very briefly discussed with Aaron on irc.

Pushed,

Mark
  

Patch

diff --git a/src/readelf.c b/src/readelf.c
index 8d96443daa83..21cacd7b6c06 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -11679,7 +11679,7 @@  print_gdb_index_section (Dwfl_Module *dwflmod, Ebl *ebl,
     }
 
   const unsigned char *const_start = data->d_buf + const_off;
-  if (const_off >= data->d_size)
+  if (const_off > data->d_size)
     goto invalid_data;
 
   const unsigned char *shortcut_start = NULL;