summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdw/dwarf_formudata.c8
-rw-r--r--libdw/dwarf_getlocation.c3
-rw-r--r--libdw/dwarf_getsrclines.c5
-rw-r--r--libdw/dwarf_ranges.c13
-rw-r--r--libdw/libdwP.h13
5 files changed, 24 insertions, 18 deletions
diff --git a/libdw/dwarf_formudata.c b/libdw/dwarf_formudata.c
index 4550b2cf..de0489db 100644
--- a/libdw/dwarf_formudata.c
+++ b/libdw/dwarf_formudata.c
@@ -57,7 +57,8 @@
internal_function unsigned char *
__libdw_formptr (Dwarf_Attribute *attr, int sec_index,
- int err_nodata, unsigned char **endpp)
+ int err_nodata, unsigned char **endpp,
+ Dwarf_Off *offsetp)
{
if (attr == NULL)
return NULL;
@@ -93,7 +94,10 @@ __libdw_formptr (Dwarf_Attribute *attr, int sec_index,
return NULL;
}
- *endpp = endp;
+ if (endpp != NULL)
+ *endpp = endp;
+ if (offsetp != NULL)
+ *offsetp = offset;
return readp;
}
diff --git a/libdw/dwarf_getlocation.c b/libdw/dwarf_getlocation.c
index 83da7cdf..8092eced 100644
--- a/libdw/dwarf_getlocation.c
+++ b/libdw/dwarf_getlocation.c
@@ -379,8 +379,7 @@ dwarf_getlocation_addr (attr, address, llbufs, listlens, maxlocs)
}
unsigned char *endp, *readp
- = __libdw_formptr (attr, IDX_debug_loc,
- DWARF_E_NO_LOCLIST, &endp);
+ = __libdw_formptr (attr, IDX_debug_loc, DWARF_E_NO_LOCLIST, &endp, NULL);
if (readp == NULL)
return -1;
diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index bc36e8b2..2158f268 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -136,9 +136,8 @@ dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines)
/* Get the offset into the .debug_line section. NB: this call
also checks whether the previous dwarf_attr call failed. */
const unsigned char *lineendp, *linep
- = __libdw_formptr (stmt_list, IDX_debug_line,
- DWARF_E_NO_DEBUG_LINE,
- (unsigned char **) &lineendp);
+ = __libdw_formptr (stmt_list, IDX_debug_line, DWARF_E_NO_DEBUG_LINE,
+ (unsigned char **) &lineendp, NULL);
if (linep == NULL)
goto out;
diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c
index d49c6ab9..68301295 100644
--- a/libdw/dwarf_ranges.c
+++ b/libdw/dwarf_ranges.c
@@ -139,13 +139,12 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
/* No PC attributes in this DIE at all, so an empty range list. */
return 0;
+ Dwarf_Word start_offset;
if ((readp = __libdw_formptr (attr, IDX_debug_ranges,
DWARF_E_NO_DEBUG_RANGES,
- &readendp)) == NULL)
+ &readendp, &start_offset)) == NULL)
return -1;
- Dwarf_Word start_offset = (void *) readp - d->d_buf;
-
offset = start_offset;
assert ((Dwarf_Word) offset == start_offset);
@@ -173,11 +172,9 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
}
else
{
- if (offset < 0 || (size_t) offset >= d->d_size)
- {
- __libdw_seterrno (DWARF_E_INVALID_OFFSET);
- return -1l;
- }
+ if (!__libdw_offset_in_section (die->cu->dbg,
+ IDX_debug_ranges, offset, 1))
+ return -1l;
readp = d->d_buf + offset;
readendp = d->d_buf + d->d_size;
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index 85b1398d..9d1bc93f 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -438,6 +438,14 @@ __libdw_in_section (Dwarf *dbg, int sec_index,
return true;
}
+static inline bool
+__libdw_offset_in_section (Dwarf *dbg, int sec_index,
+ Dwarf_Off offset, int width)
+{
+ Elf_Data *data = dbg->sectiondata[sec_index];
+ return __libdw_in_section (dbg, sec_index, data->d_buf + offset, width);
+}
+
/* Relocation hooks return -1 on error, 0 if there is no relocation
and 1 if a relocation was present.*/
int __libdw_relocate_address (Dwarf *dbg,
@@ -490,8 +498,7 @@ __libdw_read_offset_inc (Dwarf *dbg,
Dwarf_Off val;
READ_AND_RELOCATE (__libdw_relocate_offset, val);
- Elf_Data *data = dbg->sectiondata[sec_ret];
- if (!__libdw_in_section (dbg, sec_ret, data->d_buf + val, width))
+ if (!__libdw_offset_in_section (dbg, sec_ret, val, width))
return -1;
*ret = val;
@@ -512,7 +519,7 @@ __libdw_read_begin_end_pair_inc (Dwarf *dbg, int sec_index,
unsigned char *
__libdw_formptr (Dwarf_Attribute *attr, int sec_index,
- int err_nodata, unsigned char **endpp)
+ int err_nodata, unsigned char **endpp, Dwarf_Off *offsetp)
internal_function;
static inline int