public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix an out of bounds array access in, find_epilogue_using_linetable
@ 2024-03-31 10:45 Bernd Edlinger
  2024-04-01  9:07 ` Tom de Vries
  0 siblings, 1 reply; 5+ messages in thread
From: Bernd Edlinger @ 2024-03-31 10:45 UTC (permalink / raw)
  To: gdb-patches

This causes random test failures like these:

FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $fba_value == $fn_fba
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: check frame-id matches
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: bt 2
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: up
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $sp_value == $::main_sp
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $fba_value == $::main_fba
FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: [string equal $fid $::main_fid]

Here the read happens below the first element of the line
table, and the test failure depends on the value that is
read from there.

Theoretically it is also possible that std::lower_bound
returns a pointer exactly at the upper bound of the line table,
also here the read value is undefined, that happens in this test:

FAIL: gdb.dwarf2/dw2-epilogue-begin.exp: confirm watchpoint doesn't trigger

Fixes: 528b729be1a2 ("gdb/dwarf2: Add support for DW_LNS_set_epilogue_begin in line-table")
---
 gdb/symtab.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 86603dfebc3..2fc8e819932 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4177,11 +4177,10 @@ find_epilogue_using_linetable (CORE_ADDR func_addr)
 	   return lte.unrelocated_pc () < pc;
 	 });
 
-      while (it->unrelocated_pc () >= unrel_start)
+      while (it > linetable->item && (--it)->unrelocated_pc () >= unrel_start)
       {
 	if (it->epilogue_begin)
 	  return {it->pc (objfile)};
-	it --;
       }
     }
   return {};
-- 
2.39.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-05 18:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-31 10:45 [PATCH] Fix an out of bounds array access in, find_epilogue_using_linetable Bernd Edlinger
2024-04-01  9:07 ` Tom de Vries
2024-04-01 16:41   ` Bernd Edlinger
2024-04-05 15:11     ` Tom de Vries
2024-04-05 18:13       ` Bernd Edlinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).