[PATCH 1/2 v2] Don't overflow in __libdw_in_section

Ulf Hermann ulf.hermann@qt.io
Fri Dec 8 15:05:00 GMT 2017


This exposes a bug in dwarf_formstring as detected by the dwarf-getmacros
test. We cannot unconditionally assume that a string is in either the
IDX_debug_info or the IDX_debug_types section as determined by
cu_sec_idx.

(Signed-off instead of Change-Id ...)

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
  libdw/ChangeLog | 4 ++++
  libdw/libdwP.h  | 3 ++-
  2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4375244..996cd2e 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-09  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* libdwP.h: Fix check for the upper border of the range in 
__libdw_in_section.
+
  2017-11-03  Mark Wielaard  <mark@klomp.org>
   	* dwarf_getlocation.c (__libdw_intern_expression): Handle
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index 78c0013..e092d8e 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -643,7 +643,8 @@ __libdw_in_section (Dwarf *dbg, int sec_index,
    if (data == NULL)
      return false;
    if (unlikely (addr < data->d_buf)
-      || unlikely (data->d_size - (addr - data->d_buf) < size))
+      || unlikely (data->d_size < size)
+      || unlikely ((size_t)(addr - data->d_buf) > data->d_size - size))
      {
        __libdw_seterrno (DWARF_E_INVALID_OFFSET);
        return false;
-- 
2.8.1.windows.1



More information about the Elfutils-devel mailing list