This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Commit: Readelf: Fix reading numeric values from the name field of Elf Notes
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Mon, 06 Mar 2017 17:20:41 +0000
- Subject: Commit: Readelf: Fix reading numeric values from the name field of Elf Notes
- Authentication-results: sourceware.org; auth=none
Hi Guys,
I am applying the patch below to fix a small snafu in the new code to
process GNU BUILD NOTEs. The specification can store numeric values
in the name field of the note, but the code in readelf was
reconstructing the original value using signed byte reads, which lead
to unwanted sign extensions.
Whilst fixing this I also found a small snafu in the code the ensured
that a name field was null terminated, so this patch fixes that as
well.
Cheers
Nick
binutils/ChangeLog
2017-03-06 Nick Clifton <nickc@redhat.com>
* readelf.c (print_gnu_build_attribute_name): Read byte values
from the name string as unsigned bytes.
(process_notes_at): Use memcpy to copy an unterminated name
string.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 3bae045..9ed8d41 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -16768,7 +16768,9 @@ print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
while (bytes --)
{
- val |= ((* name ++) << shift);
+ unsigned long byte = (* name ++) & 0xff;
+
+ val |= byte << shift;
shift += 8;
}
@@ -17042,7 +17044,7 @@ process_notes_at (FILE * file,
break;
}
- strncpy (temp, inote.namedata, inote.namesz);
+ memcpy (temp, inote.namedata, inote.namesz);
temp[inote.namesz] = 0;
/* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */