Fix a problem in readelf where memcpy could be called with a NULL second argument.
authorNick Clifton <nickc@redhat.com>
Tue, 6 Sep 2016 14:42:12 +0000 (15:42 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 6 Sep 2016 14:42:12 +0000 (15:42 +0100)
* readelf.c (request_dump_bynumber): Only call memcpy if
dump_sects is not NULL.

binutils/ChangeLog
binutils/readelf.c

index 5ab28f8079bd98048eefe35211ffe9aa987d6512..4b3a746db954ac7988c465dcf35bb68fc62bc340 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-06  Nick Clifton  <nickc@redhat.com>
+
+       * readelf.c (request_dump_bynumber): Only call memcpy if
+       dump_sects is not NULL.
+
 2016-08-29  H.J. Lu  <hongjiu.lu@intel.com>
 
        * readelf.c (load_specific_debug_section): Check the external
index a99c521c123541aa99a0857bcbd5c76181e94d7d..c9bce2e5cb35484e927afe15485a3df76633db3c 100644 (file)
@@ -4238,10 +4238,13 @@ request_dump_bynumber (unsigned int section, dump_type type)
        error (_("Out of memory allocating dump request table.\n"));
       else
        {
-         /* Copy current flag settings.  */
-         memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
+         if (dump_sects)
+           {
+             /* Copy current flag settings.  */
+             memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
 
-         free (dump_sects);
+             free (dump_sects);
+           }
 
          dump_sects = new_dump_sects;
          num_dump_sects = section + 1;