This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: Add sanity check to dwarf1.c
- To: Chris McCann <cwmccann at syscor dot com>
- Subject: PATCH: Add sanity check to dwarf1.c
- From: "H . J . Lu" <hjl at lucon dot org>
- Date: Fri, 14 Sep 2001 17:49:56 -0700
- Cc: binutils at sourceware dot cygnus dot com
"objdump -d -S" dumps core on some bogus DWARF 1 files. Here is a
patch.
H.J.
----
2001-09-14 H.J. Lu <hjl@gnu.org>
* dwarf1.c (parse_die): Take a new arg for the end of the
section. Return false if die is beyond the section.
(parse_functions_in_unit): Pass the end of the section to
parse_die ().
(_bfd_dwarf1_find_nearest_line): Likewise.
Index: dwarf1.c
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/dwarf1.c,v
retrieving revision 1.1.1.8
diff -u -p -r1.1.1.8 dwarf1.c
--- dwarf1.c 2001/08/10 16:47:37 1.1.1.8
+++ dwarf1.c 2001/09/15 00:28:35
@@ -129,7 +129,7 @@ struct linenumber {
static struct dwarf1_unit *alloc_dwarf1_unit PARAMS ((struct dwarf1_debug *));
static struct dwarf1_func *alloc_dwarf1_func
PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
-static boolean parse_die PARAMS ((bfd *, struct die_info *, char *));
+static boolean parse_die PARAMS ((bfd *, struct die_info *, char *, char *));
static boolean parse_line_table
PARAMS ((struct dwarf1_debug *, struct dwarf1_unit *));
static boolean parse_functions_in_unit
@@ -179,10 +179,11 @@ alloc_dwarf1_func (stash, aUnit)
Return false if the die is invalidly formatted; true otherwise. */
static boolean
-parse_die (abfd, aDieInfo, aDiePtr)
+parse_die (abfd, aDieInfo, aDiePtr, aDiePtrEnd)
bfd* abfd;
struct die_info* aDieInfo;
char* aDiePtr;
+ char* aDiePtrEnd;
{
char* this_die = aDiePtr;
char* xptr = this_die;
@@ -192,7 +193,8 @@ parse_die (abfd, aDieInfo, aDiePtr)
/* First comes the length. */
aDieInfo->length = bfd_get_32 (abfd, (bfd_byte *) xptr);
xptr += 4;
- if (aDieInfo->length == 0)
+ if (aDieInfo->length == 0
+ || (this_die + aDieInfo->length) >= aDiePtrEnd)
return false;
if (aDieInfo->length < 6)
{
@@ -360,7 +362,8 @@ parse_functions_in_unit (stash, aUnit)
{
struct die_info eachDieInfo;
- if (! parse_die (stash->abfd, &eachDieInfo, eachDie))
+ if (! parse_die (stash->abfd, &eachDieInfo, eachDie,
+ stash->debug_section_end))
return false;
if (eachDieInfo.tag == TAG_global_subroutine
@@ -534,7 +537,8 @@ _bfd_dwarf1_find_nearest_line (abfd, sec
{
struct die_info aDieInfo;
- if (! parse_die (stash->abfd, &aDieInfo, stash->currentDie))
+ if (! parse_die (stash->abfd, &aDieInfo, stash->currentDie,
+ stash->debug_section_end))
return false;
if (aDieInfo.tag == TAG_compile_unit)