Automatic date update in version.in
[deliverable/binutils-gdb.git] / bfd / dwarf1.c
index 71bc57bfdf825092c3449ba8810b0efa7b54bb8b..7ff80f336a7ac409d77d3ca17e04f5bcffd573ab 100644 (file)
@@ -1,5 +1,5 @@
 /* DWARF 1 find nearest line (_bfd_dwarf1_find_nearest_line).
-   Copyright (C) 1998-2018 Free Software Foundation, Inc.
+   Copyright (C) 1998-2020 Free Software Foundation, Inc.
 
    Written by Gavin Romig-Koch of Cygnus Solutions (gavin@cygnus.com).
 
@@ -140,7 +140,7 @@ struct linenumber
 static struct dwarf1_unit*
 alloc_dwarf1_unit (struct dwarf1_debug* stash)
 {
-  bfd_size_type amt = sizeof (struct dwarf1_unit);
+  size_t amt = sizeof (struct dwarf1_unit);
 
   struct dwarf1_unit* x = (struct dwarf1_unit *) bfd_zalloc (stash->abfd, amt);
   if (x)
@@ -158,7 +158,7 @@ alloc_dwarf1_unit (struct dwarf1_debug* stash)
 static struct dwarf1_func *
 alloc_dwarf1_func (struct dwarf1_debug* stash, struct dwarf1_unit* aUnit)
 {
-  bfd_size_type amt = sizeof (struct dwarf1_func);
+  size_t amt = sizeof (struct dwarf1_func);
 
   struct dwarf1_func* x = (struct dwarf1_func *) bfd_zalloc (stash->abfd, amt);
   if (x)
@@ -213,6 +213,7 @@ parse_die (bfd *         abfd,
   /* Then the attributes.  */
   while (xptr + 2 <= aDiePtrEnd)
     {
+      unsigned int   block_len;
       unsigned short attr;
 
       /* Parse the attribute based on its form.  This section
@@ -255,12 +256,24 @@ parse_die (bfd *       abfd,
          break;
        case FORM_BLOCK2:
          if (xptr + 2 <= aDiePtrEnd)
-           xptr += bfd_get_16 (abfd, xptr);
+           {
+             block_len = bfd_get_16 (abfd, xptr);
+             if (xptr + block_len > aDiePtrEnd
+                 || xptr + block_len < xptr)
+               return FALSE;
+             xptr += block_len;
+           }
          xptr += 2;
          break;
        case FORM_BLOCK4:
          if (xptr + 4 <= aDiePtrEnd)
-           xptr += bfd_get_32 (abfd, xptr);
+           {
+             block_len = bfd_get_32 (abfd, xptr);
+             if (xptr + block_len > aDiePtrEnd
+                 || xptr + block_len < xptr)
+               return FALSE;
+             xptr += block_len;
+           }
          xptr += 4;
          break;
        case FORM_STRING:
This page took 0.023774 seconds and 4 git commands to generate.