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

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