Blame SOURCES/binutils-CVE-2019-9075.patch

0c74e2
diff -rup binutils.orig/bfd/archive64.c binutils-2.31.1/bfd/archive64.c
0c74e2
--- binutils.orig/bfd/archive64.c	2019-02-26 11:17:11.882530151 +0000
0c74e2
+++ binutils-2.31.1/bfd/archive64.c	2019-02-26 11:19:18.422488805 +0000
0c74e2
@@ -100,8 +100,6 @@ _bfd_archive_64_bit_slurp_armap (bfd *ab
0c74e2
     return FALSE;
0c74e2
   carsyms = ardata->symdefs;
0c74e2
   stringbase = ((char *) ardata->symdefs) + carsym_size;
0c74e2
-  stringbase[stringsize] = 0;
0c74e2
-  stringend = stringbase + stringsize;
0c74e2
 
0c74e2
   raw_armap = (bfd_byte *) bfd_alloc (abfd, ptrsize);
0c74e2
   if (raw_armap == NULL)
0c74e2
@@ -115,15 +113,17 @@ _bfd_archive_64_bit_slurp_armap (bfd *ab
0c74e2
       goto release_raw_armap;
0c74e2
     }
0c74e2
 
0c74e2
+  stringend = stringbase + stringsize;
0c74e2
+  *stringend = 0;
0c74e2
   for (i = 0; i < nsymz; i++)
0c74e2
     {
0c74e2
       carsyms->file_offset = bfd_getb64 (raw_armap + i * 8);
0c74e2
       carsyms->name = stringbase;
0c74e2
-      if (stringbase < stringend)
0c74e2
-	stringbase += strlen (stringbase) + 1;
0c74e2
+      stringbase += strlen (stringbase);
0c74e2
+      if (stringbase != stringend)
0c74e2
+	++stringbase;
0c74e2
       ++carsyms;
0c74e2
     }
0c74e2
-  *stringbase = '\0';
0c74e2
 
0c74e2
   ardata->symdef_count = nsymz;
0c74e2
   ardata->first_file_filepos = bfd_tell (abfd);
0c74e2
diff -rup binutils.orig/bfd/archive.c binutils-2.31.1/bfd/archive.c
0c74e2
--- binutils.orig/bfd/archive.c	2019-02-26 11:17:11.884530134 +0000
0c74e2
+++ binutils-2.31.1/bfd/archive.c	2019-02-26 11:18:33.354859687 +0000
0c74e2
@@ -1014,6 +1014,7 @@ do_slurp_coff_armap (bfd *abfd)
0c74e2
   int *raw_armap, *rawptr;
0c74e2
   struct artdata *ardata = bfd_ardata (abfd);
0c74e2
   char *stringbase;
0c74e2
+  char *stringend;
0c74e2
   bfd_size_type stringsize;
0c74e2
   bfd_size_type parsed_size;
0c74e2
   carsym *carsyms;
0c74e2
@@ -1073,22 +1074,20 @@ do_slurp_coff_armap (bfd *abfd)
0c74e2
     }
0c74e2
 
0c74e2
   /* OK, build the carsyms.  */
0c74e2
-  for (i = 0; i < nsymz && stringsize > 0; i++)
0c74e2
+  stringend = stringbase + stringsize;
0c74e2
+  *stringend = 0;
0c74e2
+  for (i = 0; i < nsymz; i++)
0c74e2
     {
0c74e2
       bfd_size_type len;
0c74e2
 
0c74e2
       rawptr = raw_armap + i;
0c74e2
       carsyms->file_offset = swap ((bfd_byte *) rawptr);
0c74e2
       carsyms->name = stringbase;
0c74e2
-      /* PR 17512: file: 4a1d50c1.  */
0c74e2
-      len = strnlen (stringbase, stringsize);
0c74e2
-      if (len < stringsize)
0c74e2
-	len ++;
0c74e2
-      stringbase += len;
0c74e2
-      stringsize -= len;
0c74e2
+      stringbase += strlen (stringbase);
0c74e2
+      if (stringbase != stringend)
0c74e2
+	++stringbase;
0c74e2
       carsyms++;
0c74e2
     }
0c74e2
-  *stringbase = 0;
0c74e2
 
0c74e2
   ardata->symdef_count = nsymz;
0c74e2
   ardata->first_file_filepos = bfd_tell (abfd);