[PATCH] debugedit: Guard that .debug_abbrev ends in a zero byte

Mark Wielaard mark@klomp.org
Wed Sep 2 12:50:41 GMT 2026


Abbrev tables end in double zeros (no attr, no form). Check that the
end of the section (last abbrev table) contains a zero (just like
string sections). This makes sure that any leb128 read from the
section termnates before the section ends.

	* tools/debugedit.c (edit_dwarf2): Add DEBUG_ABBREV to
	sections that should be zero terminated.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tools/debugedit.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/debugedit.c b/tools/debugedit.c
index 9697dbac27b2..8f0dad4e4223 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -3138,8 +3138,14 @@ edit_dwarf2 (DSO *dso)
 		  debug_sec->size = data->d_size;
 		  debug_sec->sec = i;
 
-		  /* String sections should end with a zero terminator.  */
-		  if ((j == DEBUG_STR || j == DEBUG_LINE_STR)
+		  /* String sections and abbrev tables should end with
+		     a zero terminator.  This makes sure strings read
+		     from these sections are always terminated and
+		     that reading an leb128 value terminates before
+		     the section ends. */
+		  if ((j == DEBUG_STR
+		       || j == DEBUG_LINE_STR
+		       || j == DEBUG_ABBREV)
 		      && debug_sec->size > 0)
 		    {
 		      if (debug_sec->data[debug_sec->size - 1] != '\0')
-- 
2.55.0



More information about the Debugedit mailing list