This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Readelf: do not pass NULL pointer to memcpy
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Tue, 06 Sep 2016 15:41:19 +0100
- Subject: Readelf: do not pass NULL pointer to memcpy
- Authentication-results: sourceware.org; auth=none
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;