This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Readelf: do not pass NULL pointer to memcpy


Hi Guys,

  Compiling the binutils with -fsanitize=undefined and then running the
  binutils testsuite revealed a problem:

    binutils/readelf.c:4242:4: runtime error: null pointer passed as argument 2, which is declared to never be null

  So I am applying the patch below to fix this issue.

Cheers
  Nick

binutils/ChangeLog
2016-09-06  Nick Clifton  <nickc@redhat.com>

	* readelf.c (request_dump_bynumber): Only call memcpy if
	dump_sects is not NULL.

diff --git a/binutils/readelf.c b/binutils/readelf.c
index a99c521..c9bce2e 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]