]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Don't crash on invalid die in dwarf_dieoffset.
authorMark Wielaard <mark@klomp.org>
Thu, 31 May 2018 11:01:39 +0000 (13:01 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 31 May 2018 17:48:00 +0000 (19:48 +0200)
Add explicit test in get-units-invalid for dwarf_cuoffset and
dwarf_dieoffset. Make sure dwarf_dieoffset returns (Dwarf_Off) -1
on failure.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_dieoffset.c
src/ChangeLog
src/readelf.c
tests/ChangeLog
tests/get-units-invalid.c

index 5a33d9c12d234d4b04e5254e88fba278f6a382fb..38b45baddc03e1a86c4e6f4b0946f295afac37d2 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-31  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_dieoffset.c: Check die->cu != NULL. Return -1, not ~0ul
+       on failure.
+
 2018-05-29  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_cuoffset.c (dwarf_cuoffset): Check die->cu is not NULL.
index 8028f6dd2af884852a2e008280c8d94caa5c1486..3a8e2cb6987a1c3769d654dfa02022a94a2878fa 100644 (file)
@@ -38,8 +38,8 @@
 Dwarf_Off
 dwarf_dieoffset (Dwarf_Die *die)
 {
-  return (die == NULL
-         ? ~0ul
+  return ((die == NULL || die->cu == NULL)
+         ? (Dwarf_Off) -1
          : (Dwarf_Off) (die->addr - die->cu->startp + die->cu->start));
 }
 INTDEF(dwarf_dieoffset)
index f424fb7f689d495cb2c48a1f1b4e8315c362a101..03ed5aabdda8d44942335152a9a59b6474dd1e19 100644 (file)
@@ -1,3 +1,7 @@
+2018-05-31  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (print_debug_units): Check offset against -1 not ~0ul.
+
 2018-05-29  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (print_debug_loc_section): Handle GNU DebugFission list
index 2ccbea5b75c31d800bd64c2cb694b534cdd06ef4..470a94eb445d6158d9eda1dd7b674caf575929bb 100644 (file)
@@ -7588,7 +7588,7 @@ print_debug_units (Dwfl_Module *dwflmod,
   do
     {
       Dwarf_Off offset = dwarf_dieoffset (&dies[level]);
-      if (unlikely (offset == ~0ul))
+      if (unlikely (offset == (Dwarf_Off) -1))
        {
          if (!silent)
            error (0, 0, gettext ("cannot get DIE offset: %s"),
index b656bee7a5828360ca118fd5367ce79d1d020799..521df52f20e97fa5248322c92b9a0c3adfd051fb 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-31  Mark Wielaard  <mark@klomp.org>
+
+       * get-units-invalid.c (main): Check dwarf_cuoffset and
+       dwarf_dieoffset.
+
 2018-05-29  Mark Wielaard  <mark@klomp.org>
 
        * dwarf-die-addr-die.c (check_dbg): Also check subdies, split or
index 58b32c0e6a57ce053740472e768ce8b7d082c84b..ba0f818d9f101675494f3fc5fec627efcdec78f4 100644 (file)
@@ -83,7 +83,19 @@ main (int argc, char *argv[])
              if (dwarf_ranges (&subdie, 0, &base, &start, &end) != -1)
                {
                  printf ("Should NOT have a ranges: %s\n",
-                         dwarf_diename (&result));
+                         dwarf_diename (&subdie));
+                 return -1;
+               }
+             if (dwarf_cuoffset (&subdie) != (Dwarf_Off) -1)
+               {
+                 printf ("Should NOT have a cuoffset: %s\n",
+                         dwarf_diename (&subdie));
+                 return -1;
+               }
+             if (dwarf_dieoffset (&subdie) != (Dwarf_Off) -1)
+               {
+                 printf ("Should NOT have a die offset: %s\n",
+                         dwarf_diename (&subdie));
                  return -1;
                }
            }