Prevent an assertion failure in readelf & objdump when parsing corrupt DWARF information.
authorNick Clifton <nickc@redhat.com>
Wed, 18 Apr 2018 11:03:03 +0000 (12:03 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 18 Apr 2018 11:03:03 +0000 (12:03 +0100)
PR 23062
* dwarf.c (read_and_display_attr_value): Replace assertions with
test and warning message.

binutils/ChangeLog
binutils/dwarf.c

index 3d28535d8817a4577a5a1f08614d6986494b2818..991ebbe4dad631ad5820ffddc5c7d81f1b191dee 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-18  Nick Clifton  <nickc@redhat.com>
+
+       PR 23062
+       * dwarf.c (read_and_display_attr_value): Replace assertions with
+       test and warning message.
+
 2018-04-18  Alan Modra  <amodra@gmail.com>
 
        * testsuite/lib/binutils-common.exp: Remove support for assorted
index f94f5b2fe699941b2f31c803da422b4c9b071d39..cd3df7fb87585e47799e1cc063dcacfe6f3c52c4 100644 (file)
@@ -2174,19 +2174,28 @@ read_and_display_attr_value (unsigned long           attribute,
              debug_info_p->have_frame_base [num] = have_frame_base;
              if (attribute != DW_AT_GNU_locviews)
                {
-                 debug_info_p->loc_offsets [num] = uvalue;
-                 debug_info_p->num_loc_offsets++;
-                 assert (debug_info_p->num_loc_offsets
-                         - debug_info_p->num_loc_views <= 1);
+                 /* Corrupt DWARF info can produce more offsets than views.
+                    See PR 23062 for an example.  */
+                 if (debug_info_p->num_loc_offsets
+                     > debug_info_p->num_loc_views)
+                   warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
+                 else
+                   {
+                     debug_info_p->loc_offsets [num] = uvalue;
+                     debug_info_p->num_loc_offsets++;
+                   }
                }
              else
                {
                  assert (debug_info_p->num_loc_views <= num);
                  num = debug_info_p->num_loc_views;
-                 debug_info_p->loc_views [num] = uvalue;
-                 debug_info_p->num_loc_views++;
-                 assert (debug_info_p->num_loc_views
-                         - debug_info_p->num_loc_offsets <= 1);
+                 if (num > debug_info_p->num_loc_offsets)
+                   warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
+                 else
+                   {
+                     debug_info_p->loc_views [num] = uvalue;
+                     debug_info_p->num_loc_views++;
+                   }
                }
            }
          break;