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

13ae24
--- binutils.orig/bfd/dwarf2.c	2018-05-01 13:04:35.055041935 +0100
13ae24
+++ binutils-2.30/bfd/dwarf2.c	2018-05-01 13:31:32.882624448 +0100
13ae24
@@ -622,14 +622,24 @@ read_8_bytes (bfd *abfd, bfd_byte *buf,
13ae24
 }
13ae24
 
13ae24
 static bfd_byte *
13ae24
-read_n_bytes (bfd *abfd ATTRIBUTE_UNUSED,
13ae24
-	      bfd_byte *buf,
13ae24
-	      bfd_byte *end,
13ae24
-	      unsigned int size ATTRIBUTE_UNUSED)
13ae24
-{
13ae24
-  if (buf + size > end)
13ae24
-    return NULL;
13ae24
-  return buf;
13ae24
+read_n_bytes (bfd_byte *           buf,
13ae24
+	      bfd_byte *           end,
13ae24
+	      struct dwarf_block * block)
13ae24
+{
13ae24
+  unsigned int  size = block->size;
13ae24
+  bfd_byte *    block_end = buf + size;
13ae24
+
13ae24
+  if (block_end > end || block_end < buf)
13ae24
+    {
13ae24
+      block->data = NULL;
13ae24
+      block->size = 0;
13ae24
+      return end;
13ae24
+    }
13ae24
+  else
13ae24
+    {
13ae24
+      block->data = buf;
13ae24
+      return block_end;
13ae24
+    }
13ae24
 }
13ae24
 
13ae24
 /* Scans a NUL terminated string starting at BUF, returning a pointer to it.
13ae24
@@ -1127,8 +1137,7 @@ read_attribute_value (struct attribute *
13ae24
 	return NULL;
13ae24
       blk->size = read_2_bytes (abfd, info_ptr, info_ptr_end);
13ae24
       info_ptr += 2;
13ae24
-      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
13ae24
-      info_ptr += blk->size;
13ae24
+      info_ptr = read_n_bytes (info_ptr, info_ptr_end, blk);
13ae24
       attr->u.blk = blk;
13ae24
       break;
13ae24
     case DW_FORM_block4:
13ae24
@@ -1138,8 +1147,7 @@ read_attribute_value (struct attribute *
13ae24
 	return NULL;
13ae24
       blk->size = read_4_bytes (abfd, info_ptr, info_ptr_end);
13ae24
       info_ptr += 4;
13ae24
-      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
13ae24
-      info_ptr += blk->size;
13ae24
+      info_ptr = read_n_bytes (info_ptr, info_ptr_end, blk);
13ae24
       attr->u.blk = blk;
13ae24
       break;
13ae24
     case DW_FORM_data2:
13ae24
@@ -1179,8 +1187,7 @@ read_attribute_value (struct attribute *
13ae24
       blk->size = _bfd_safe_read_leb128 (abfd, info_ptr, &bytes_read,
13ae24
 					 FALSE, info_ptr_end);
13ae24
       info_ptr += bytes_read;
13ae24
-      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
13ae24
-      info_ptr += blk->size;
13ae24
+      info_ptr = read_n_bytes (info_ptr, info_ptr_end, blk);
13ae24
       attr->u.blk = blk;
13ae24
       break;
13ae24
     case DW_FORM_block1:
13ae24
@@ -1190,8 +1197,7 @@ read_attribute_value (struct attribute *
13ae24
 	return NULL;
13ae24
       blk->size = read_1_byte (abfd, info_ptr, info_ptr_end);
13ae24
       info_ptr += 1;
13ae24
-      blk->data = read_n_bytes (abfd, info_ptr, info_ptr_end, blk->size);
13ae24
-      info_ptr += blk->size;
13ae24
+      info_ptr = read_n_bytes (info_ptr, info_ptr_end, blk);
13ae24
       attr->u.blk = blk;
13ae24
       break;
13ae24
     case DW_FORM_data1: