From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 2/2] gdb: safety checks in skip_prologue_using_sal
Date: Thu, 18 May 2023 09:37:55 +0100 [thread overview]
Message-ID: <74b814d3c7621df2d09945579829194e33a4ccf4.1684398918.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1684398918.git.aburgess@redhat.com>
While working on the previous patch I reverted this commit:
commit e86e87f77fd5d8afb3e714f1d9e09e0ff5b4e6ff
Date: Tue Nov 28 16:23:32 2006 +0000
* symtab.c (find_pc_sect_line): Do not return a line before
the start of a symtab.
When I re-ran the testsuite I saw some GDB crashes in the tests:
gdb.dwarf2/dw2-line-number-zero.exp
gdb.dwarf2/dw2-lines.exp
gdb.dwarf2/dw2-vendor-extended-opcode.exp
GDB was reading beyond the end of an array in the function
skip_prologue_using_sal.
Now, without the above commit reverted I don't believe that this
should ever happen. Reverting the above commit effectively breaks
GDB's symtab_and_line lookup, we try to find a result for an address,
and return the wrong symtab and line-table. In
skip_prologue_using_sal we then walk the line table looking for an
appropriate entry, except we never find one, and GDB just keeps going,
wandering off the end of the array.
However, I think adding extra protection to prevent walking off the
end of the array is pretty cheap, and if something does go wrong in
the future then this should prevent a random crash.
Obviously, I have no reproducer for this, as I said, I don't think
this should impact GDB at all, this is just adding a little extra
caution.
---
gdb/symtab.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 4f28667b1b3..5e1b9d91879 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3953,15 +3953,17 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
struct objfile *objfile
= prologue_sal.symtab->compunit ()->objfile ();
const linetable *linetable = prologue_sal.symtab->linetable ();
+ gdb_assert (linetable->nitems > 0);
int idx = 0;
/* Skip any earlier lines, and any end-of-sequence marker
from a previous function. */
- while (linetable->item[idx].pc (objfile) != prologue_sal.pc
- || linetable->item[idx].line == 0)
+ while (idx + 1 < linetable->nitems
+ && (linetable->item[idx].pc (objfile) != prologue_sal.pc
+ || linetable->item[idx].line == 0))
idx++;
- if (idx+1 < linetable->nitems
+ if (idx + 1 < linetable->nitems
&& linetable->item[idx+1].line != 0
&& linetable->item[idx+1].pc (objfile) == start_pc)
return start_pc;
--
2.25.4
next prev parent reply other threads:[~2023-05-18 8:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 8:37 [PATCH 0/2] New test for find_pc_sect_line Andrew Burgess
2023-05-18 8:37 ` [PATCH 1/2] gdb/testsuite: test for a function with no line table Andrew Burgess
2023-05-18 8:37 ` Andrew Burgess [this message]
2023-05-18 17:22 ` [PATCH 0/2] New test for find_pc_sect_line Tom Tromey
2023-05-19 10:06 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=74b814d3c7621df2d09945579829194e33a4ccf4.1684398918.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).