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

869a11
--- binutils.orig/bfd/opncls.c	2018-05-01 11:42:03.266424248 +0100
869a11
+++ binutils-2.30/bfd/opncls.c	2018-05-01 12:52:36.792579838 +0100
869a11
@@ -1179,6 +1179,7 @@ bfd_get_debug_link_info_1 (bfd *abfd, vo
869a11
   bfd_byte *contents;
869a11
   unsigned int crc_offset;
869a11
   char *name;
869a11
+  bfd_size_type size;
869a11
 
869a11
   BFD_ASSERT (abfd);
869a11
   BFD_ASSERT (crc32_out);
869a11
@@ -1188,6 +1189,12 @@ bfd_get_debug_link_info_1 (bfd *abfd, vo
869a11
   if (sect == NULL)
869a11
     return NULL;
869a11
 
869a11
+  size = bfd_get_section_size (sect);
869a11
+
869a11
+  /* PR 22794: Make sure that the section has a reasonable size.  */
869a11
+  if (size < 8 || size >= bfd_get_size (abfd))
869a11
+    return NULL;
869a11
+
869a11
   if (!bfd_malloc_and_get_section (abfd, sect, &contents))
869a11
     {
869a11
       if (contents != NULL)
869a11
@@ -1198,9 +1205,9 @@ bfd_get_debug_link_info_1 (bfd *abfd, vo
869a11
   /* CRC value is stored after the filename, aligned up to 4 bytes.  */
869a11
   name = (char *) contents;
869a11
   /* PR 17597: avoid reading off the end of the buffer.  */
869a11
-  crc_offset = strnlen (name, bfd_get_section_size (sect)) + 1;
869a11
+  crc_offset = strnlen (name, size) + 1;
869a11
   crc_offset = (crc_offset + 3) & ~3;
869a11
-  if (crc_offset + 4 > bfd_get_section_size (sect))
869a11
+  if (crc_offset + 4 > size)
869a11
     return NULL;
869a11
 
869a11
   *crc32 = bfd_get_32 (abfd, contents + crc_offset);
869a11
@@ -1261,6 +1268,7 @@ bfd_get_alt_debug_link_info (bfd * abfd,
869a11
   bfd_byte *contents;
869a11
   unsigned int buildid_offset;
869a11
   char *name;
869a11
+  bfd_size_type size;
869a11
 
869a11
   BFD_ASSERT (abfd);
869a11
   BFD_ASSERT (buildid_len);
869a11
@@ -1271,6 +1279,10 @@ bfd_get_alt_debug_link_info (bfd * abfd,
869a11
   if (sect == NULL)
869a11
     return NULL;
869a11
 
869a11
+  size = bfd_get_section_size (sect);
869a11
+  if (size < 8 || size >= bfd_get_size (abfd))
869a11
+    return NULL;
869a11
+
869a11
   if (!bfd_malloc_and_get_section (abfd, sect, & contents))
869a11
     {
869a11
       if (contents != NULL)
869a11
@@ -1280,11 +1292,11 @@ bfd_get_alt_debug_link_info (bfd * abfd,
869a11
 
869a11
   /* BuildID value is stored after the filename.  */
869a11
   name = (char *) contents;
869a11
-  buildid_offset = strnlen (name, bfd_get_section_size (sect)) + 1;
869a11
-  if (buildid_offset >= bfd_get_section_size (sect))
869a11
+  buildid_offset = strnlen (name, size) + 1;
869a11
+  if (buildid_offset >= size)
869a11
     return NULL;
869a11
 
869a11
-  *buildid_len = bfd_get_section_size (sect) - buildid_offset;
869a11
+  *buildid_len = size - buildid_offset;
869a11
   *buildid_out = bfd_malloc (*buildid_len);
869a11
   memcpy (*buildid_out, contents + buildid_offset, *buildid_len);
869a11