PR22361 readelf buffer overflow on fuzzed archive header
authorAlan Modra <amodra@gmail.com>
Sat, 28 Oct 2017 11:01:16 +0000 (21:31 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 28 Oct 2017 11:42:46 +0000 (22:12 +1030)
PR 22361
* readelf.c (process_archive_index_and_symbols): Ensure ar_size
field is zero terminated for strtoul.
(setup_archive, get_archive_member_name): Likewise.

binutils/ChangeLog
binutils/elfcomm.c

index 8d77c68b912b7b3983ba767cb87ef12e22623248..d0cd3c7038d191c1660b229aae87f751461437d4 100644 (file)
@@ -1,3 +1,10 @@
+2017-10-28  Alan Modra  <amodra@gmail.com>
+
+       PR 22361
+       * readelf.c (process_archive_index_and_symbols): Ensure ar_size
+       field is zero terminated for strtoul.
+       (setup_archive, get_archive_member_name): Likewise.
+
 2017-10-27  Simon Marchi  <simon.marchi@ericsson.com>
 
        * dwarf.c (struct Frame_Chunk) <cfa_reg>: Change type to
index 0db8948775054192d43ba3a46641f24483c34d88..80f3fd8e9a58caf88f30bcd4a3c966c15b31f6b6 100644 (file)
@@ -466,8 +466,12 @@ process_archive_index_and_symbols (struct archive_info *  arch,
 {
   size_t got;
   unsigned long size;
+  char fmag_save;
 
+  fmag_save = arch->arhdr.ar_fmag[0];
+  arch->arhdr.ar_fmag[0] = 0;
   size = strtoul (arch->arhdr.ar_size, NULL, 10);
+  arch->arhdr.ar_fmag[0] = fmag_save;
   /* PR 17531: file: 912bd7de.  */
   if ((signed long) size < 0)
     {
@@ -655,7 +659,10 @@ setup_archive (struct archive_info *arch, const char *file_name,
   if (const_strneq (arch->arhdr.ar_name, "//              "))
     {
       /* This is the archive string table holding long member names.  */
+      char fmag_save = arch->arhdr.ar_fmag[0];
+      arch->arhdr.ar_fmag[0] = 0;
       arch->longnames_size = strtoul (arch->arhdr.ar_size, NULL, 10);
+      arch->arhdr.ar_fmag[0] = fmag_save;
       /* PR 17531: file: 01068045.  */
       if (arch->longnames_size < 8)
        {
@@ -758,6 +765,7 @@ get_archive_member_name (struct archive_info *arch,
       char *endp;
       char *member_file_name;
       char *member_name;
+      char fmag_save;
 
       if (arch->longnames == NULL || arch->longnames_size == 0)
        {
@@ -766,9 +774,12 @@ get_archive_member_name (struct archive_info *arch,
        }
 
       arch->nested_member_origin = 0;
+      fmag_save = arch->arhdr.ar_fmag[0];
+      arch->arhdr.ar_fmag[0] = 0;
       k = j = strtoul (arch->arhdr.ar_name + 1, &endp, 10);
       if (arch->is_thin_archive && endp != NULL && * endp == ':')
         arch->nested_member_origin = strtoul (endp + 1, NULL, 10);
+      arch->arhdr.ar_fmag[0] = fmag_save;
 
       if (j > arch->longnames_size)
        {
This page took 0.026472 seconds and 4 git commands to generate.