x86-64: Don't pass output_bfd to info->callbacks->minfo
[binutils-gdb.git] / bfd / dwarf2.c
index ad06120b96f5bda6abd36b7f77735aff2fa42932..be415e394a36e3659bec6195c50f1c9b551d0d83 100644 (file)
@@ -1938,6 +1938,16 @@ read_formatted_entries (struct comp_unit *unit, bfd_byte **bufp,
       return FALSE;
     }
 
+  /* PR 22210.  Paranoia check.  Don't bother running the loop
+     if we know that we are going to run out of buffer.  */
+  if (data_count > (bfd_vma) (buf_end - buf))
+    {
+      _bfd_error_handler (_("Dwarf Error: data count (%Lx) larger than buffer size."),
+                         data_count);
+      bfd_set_error (bfd_error_bad_value);
+      return FALSE;
+    }
+
   for (datai = 0; datai < data_count; datai++)
     {
       bfd_byte *format = format_header_data;
@@ -1950,6 +1960,7 @@ read_formatted_entries (struct comp_unit *unit, bfd_byte **bufp,
          char *string_trash;
          char **stringp = &string_trash;
          unsigned int uint_trash, *uintp = &uint_trash;
+         struct attribute attr;
 
          content_type = _bfd_safe_read_leb128 (abfd, format, &bytes_read,
                                                FALSE, buf_end);
@@ -1981,47 +1992,23 @@ read_formatted_entries (struct comp_unit *unit, bfd_byte **bufp,
          form = _bfd_safe_read_leb128 (abfd, format, &bytes_read, FALSE,
                                        buf_end);
          format += bytes_read;
+
+         buf = read_attribute_value (&attr, form, 0, unit, buf, buf_end);
+         if (buf == NULL)
+           return FALSE;
          switch (form)
            {
            case DW_FORM_string:
-             *stringp = read_string (abfd, buf, buf_end, &bytes_read);
-             buf += bytes_read;
-             break;
-
            case DW_FORM_line_strp:
-             *stringp = read_indirect_line_string (unit, buf, buf_end, &bytes_read);
-             buf += bytes_read;
+             *stringp = attr.u.str;
              break;
 
            case DW_FORM_data1:
-             *uintp = read_1_byte (abfd, buf, buf_end);
-             buf += 1;
-             break;
-
            case DW_FORM_data2:
-             *uintp = read_2_bytes (abfd, buf, buf_end);
-             buf += 2;
-             break;
-
            case DW_FORM_data4:
-             *uintp = read_4_bytes (abfd, buf, buf_end);
-             buf += 4;
-             break;
-
            case DW_FORM_data8:
-             *uintp = read_8_bytes (abfd, buf, buf_end);
-             buf += 8;
-             break;
-
            case DW_FORM_udata:
-             *uintp = _bfd_safe_read_leb128 (abfd, buf, &bytes_read, FALSE,
-                                             buf_end);
-             buf += bytes_read;
-             break;
-
-           case DW_FORM_block:
-             /* It is valid only for DW_LNCT_timestamp which is ignored by
-                current GDB.  */
+             *uintp = attr.u.val;
              break;
            }
        }