Blame SOURCES/binutils-CVE-2018-7568.patch

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