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

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