49857a
--- binutils.orig/bfd/dwarf1.c	2018-05-15 17:25:27.656131299 +0100
49857a
+++ binutils-2.27/bfd/dwarf1.c	2018-05-15 17:29:04.176057372 +0100
49857a
@@ -208,6 +208,7 @@ parse_die (bfd *             abfd,
49857a
   /* Then the attributes.  */
49857a
   while (xptr < (this_die + aDieInfo->length))
49857a
     {
49857a
+      unsigned int   block_len;
49857a
       unsigned short attr;
49857a
 
49857a
       /* Parse the attribute based on its form.  This section
49857a
@@ -223,12 +224,15 @@ parse_die (bfd *             abfd,
49857a
 	  break;
49857a
 	case FORM_DATA4:
49857a
 	case FORM_REF:
49857a
-	  if (attr == AT_sibling)
49857a
-	    aDieInfo->sibling = bfd_get_32 (abfd, (bfd_byte *) xptr);
49857a
-	  else if (attr == AT_stmt_list)
49857a
+	  if (xptr + 4 <= aDiePtrEnd)
49857a
 	    {
49857a
-	      aDieInfo->stmt_list_offset = bfd_get_32 (abfd, (bfd_byte *) xptr);
49857a
-	      aDieInfo->has_stmt_list = 1;
49857a
+	      if (attr == AT_sibling)
49857a
+		aDieInfo->sibling = bfd_get_32 (abfd, xptr);
49857a
+	      else if (attr == AT_stmt_list)
49857a
+		{
49857a
+		  aDieInfo->stmt_list_offset = bfd_get_32 (abfd, xptr);
49857a
+		  aDieInfo->has_stmt_list = 1;
49857a
+		}
49857a
 	    }
49857a
 	  xptr += 4;
49857a
 	  break;
49857a
@@ -236,22 +240,41 @@ parse_die (bfd *             abfd,
49857a
 	  xptr += 8;
49857a
 	  break;
49857a
 	case FORM_ADDR:
49857a
-	  if (attr == AT_low_pc)
49857a
-	    aDieInfo->low_pc = bfd_get_32 (abfd, (bfd_byte *) xptr);
49857a
-	  else if (attr == AT_high_pc)
49857a
-	    aDieInfo->high_pc = bfd_get_32 (abfd, (bfd_byte *) xptr);
49857a
+	  if (xptr + 4 <= aDiePtrEnd)
49857a
+	    {
49857a
+	      if (attr == AT_low_pc)
49857a
+		aDieInfo->low_pc = bfd_get_32 (abfd, xptr);
49857a
+	      else if (attr == AT_high_pc)
49857a
+		aDieInfo->high_pc = bfd_get_32 (abfd, xptr);
49857a
+	    }
49857a
 	  xptr += 4;
49857a
 	  break;
49857a
 	case FORM_BLOCK2:
49857a
-	  xptr += 2 + bfd_get_16 (abfd, (bfd_byte *) xptr);
49857a
+	  if (xptr + 2 <= aDiePtrEnd)
49857a
+	    {
49857a
+	      block_len = bfd_get_16 (abfd, xptr);
49857a
+	      if (xptr + block_len > aDiePtrEnd
49857a
+		  || xptr + block_len < xptr)
49857a
+		return FALSE;
49857a
+	      xptr += block_len;
49857a
+	    }
49857a
+	  xptr += 2;
49857a
 	  break;
49857a
 	case FORM_BLOCK4:
49857a
-	  xptr += 4 + bfd_get_32 (abfd, (bfd_byte *) xptr);
49857a
+	  if (xptr + 4 <= aDiePtrEnd)
49857a
+	    {
49857a
+	      block_len = bfd_get_32 (abfd, xptr);
49857a
+	      if (xptr + block_len > aDiePtrEnd
49857a
+		  || xptr + block_len < xptr)
49857a
+		return FALSE;
49857a
+	      xptr += block_len;
49857a
+	    }
49857a
+	  xptr += 4;
49857a
 	  break;
49857a
 	case FORM_STRING:
49857a
 	  if (attr == AT_name)
49857a
 	    aDieInfo->name = (char *) xptr;
49857a
-	  xptr += strlen ((char *) xptr) + 1;
49857a
+	  xptr += strnlen ((char *) xptr, aDiePtrEnd - xptr) + 1;
49857a
 	  break;
49857a
 	}
49857a
     }