aboutsummaryrefslogtreecommitdiff
path: root/binutils/readelf.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-03-08 07:44:04 -0800
committerH.J. Lu <hjl.tools@gmail.com>2017-03-08 07:44:17 -0800
commit1fc87489b40b3100badf184a7c266387bae47def (patch)
tree0b929911ff8427f908a0dbd180e473f589bcdc98 /binutils/readelf.c
parent2e86a2830cfef688a27e17353b84f59f8147ab23 (diff)
downloadgdb-1fc87489b40b3100badf184a7c266387bae47def.zip
gdb-1fc87489b40b3100badf184a7c266387bae47def.tar.gz
gdb-1fc87489b40b3100badf184a7c266387bae47def.tar.bz2
Properly dump NT_GNU_PROPERTY_TYPE_0
Property type and datasz are always 4 bytes for both 32-bit and 64-bit objects. Property values for GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED are 4 bytes for both i386 and x86-64 objects. We should also check GNU_PROPERTY_LOPROC and GNU_PROPERTY_LOUSER. binutils/ PR binutils/21231 * readelf.c (decode_x86_isa): Change argument to unsigned int. (print_gnu_property_note): Retrieve property type and datasz as 4-byte integer. Consolidate property datasz check. Check GNU_PROPERTY_LOPROC and GNU_PROPERTY_LOUSER. * testsuite/binutils-all/i386/pr21231a.d: New file. * testsuite/binutils-all/i386/pr21231a.s: Likewise. * testsuite/binutils-all/i386/pr21231b.d: Likewise. * testsuite/binutils-all/i386/pr21231b.s: Likewise. * testsuite/binutils-all/x86-64/pr21231a.d: Likewise. * testsuite/binutils-all/x86-64/pr21231a.s: Likewise. * testsuite/binutils-all/x86-64/pr21231b.d: Likewise. * testsuite/binutils-all/x86-64/pr21231b.s: Likewise. include/ PR binutils/21231 * elf/common.h (GNU_PROPERTY_LOPROC): New. (GNU_PROPERTY_HIPROC): Likewise. (GNU_PROPERTY_LOUSER): Likewise. (GNU_PROPERTY_HIUSER): Likewise.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r--binutils/readelf.c123
1 files changed, 78 insertions, 45 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 9ed8d41..bf5185a 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -15926,11 +15926,11 @@ get_gnu_elf_note_type (unsigned e_type)
}
static void
-decode_x86_isa (unsigned long bitmask)
+decode_x86_isa (unsigned int bitmask)
{
while (bitmask)
{
- unsigned long bit = bitmask & (- bitmask);
+ unsigned int bit = bitmask & (- bitmask);
bitmask &= ~ bit;
switch (bit)
@@ -15953,7 +15953,7 @@ decode_x86_isa (unsigned long bitmask)
case GNU_PROPERTY_X86_ISA_1_AVX512VL: printf ("AVX512VL"); break;
case GNU_PROPERTY_X86_ISA_1_AVX512DQ: printf ("AVX512DQ"); break;
case GNU_PROPERTY_X86_ISA_1_AVX512BW: printf ("AVX512BW"); break;
- default: printf (_("<unknown: %lx>"), bit); break;
+ default: printf (_("<unknown: %x>"), bit); break;
}
if (bitmask)
printf (", ");
@@ -15969,73 +15969,106 @@ print_gnu_property_note (Elf_Internal_Note * pnote)
printf (_(" Properties: "));
- if (pnote->descsz % size)
+ if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
{
printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
return;
}
- while (ptr < (ptr_end - (size * 2)))
+ while (1)
{
- unsigned long j;
- unsigned long type = byte_get (ptr, size);
- unsigned long datasz = byte_get (ptr + size, size);
+ unsigned int j;
+ unsigned int type = byte_get (ptr, 4);
+ unsigned int datasz = byte_get (ptr + 4, 4);
- ptr += 2 * size;
+ ptr += 8;
- switch (type)
+ if ((ptr + datasz) > ptr_end)
{
- case GNU_PROPERTY_STACK_SIZE:
- printf (_("stack size: "));
- if (datasz != size || (ptr + size > ptr_end))
- printf (_("<corrupt length: %#lx> "), datasz);
- else
- printf ("%#lx", (unsigned long) byte_get (ptr, size));
- break;
-
- case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
- printf ("no copy on protected ");
- if (datasz)
- printf (_("<corrupt length: %#lx> "), datasz);
+ printf (_("<corrupt type (%#x) datasz: %#x>\n"),
+ type, datasz);
break;
+ }
- case GNU_PROPERTY_X86_ISA_1_USED:
- printf ("x86 ISA used: ");
- if (datasz != size || (ptr + size > ptr_end))
- printf (_("<corrupt length: %#lx> "), datasz);
- else
- decode_x86_isa (byte_get (ptr, size));
- break;
+ if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
+ {
+ if (elf_header.e_machine == EM_X86_64
+ || elf_header.e_machine == EM_IAMCU
+ || elf_header.e_machine == EM_386)
+ {
+ switch (type)
+ {
+ case GNU_PROPERTY_X86_ISA_1_USED:
+ printf ("x86 ISA used: ");
+ if (datasz != 4)
+ printf (_("<corrupt length: %#x> "), datasz);
+ else
+ decode_x86_isa (byte_get (ptr, 4));
+ goto next;
- case GNU_PROPERTY_X86_ISA_1_NEEDED:
- printf ("x86 ISA needed: ");
- if (datasz != size || (ptr + size > ptr_end))
- printf (_("<corrupt length: %#lx> "), datasz);
- else
- decode_x86_isa (byte_get (ptr, size));
- break;
+ case GNU_PROPERTY_X86_ISA_1_NEEDED:
+ printf ("x86 ISA needed: ");
+ if (datasz != 4)
+ printf (_("<corrupt length: %#x> "), datasz);
+ else
+ decode_x86_isa (byte_get (ptr, 4));
+ goto next;
- default:
- printf (_("<unknown type %#lx data: "), type);
- if (ptr + datasz > ptr_end)
+ default:
+ break;
+ }
+ }
+ }
+ else
+ {
+ switch (type)
{
- printf (_("corrupt datasz: %#lx>\n"), datasz);
+ case GNU_PROPERTY_STACK_SIZE:
+ printf (_("stack size: "));
+ if (datasz != size)
+ printf (_("<corrupt length: %#x> "), datasz);
+ else
+ printf ("%#lx", (unsigned long) byte_get (ptr, size));
+ goto next;
+
+ case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
+ printf ("no copy on protected ");
+ if (datasz)
+ printf (_("<corrupt length: %#x> "), datasz);
+ goto next;
+
+ default:
break;
}
- for (j = 0; j < datasz; ++j)
- printf ("%02x ", ptr[j] & 0xff);
- printf (">");
- break;
}
+ if (type < GNU_PROPERTY_LOPROC)
+ printf (_("<unknown type %#x data: "), type);
+ else if (type < GNU_PROPERTY_LOUSER)
+ printf (_("<procesor-specific type %#x data: "), type);
+ else
+ printf (_("<application-specific type %#x data: "), type);
+ for (j = 0; j < datasz; ++j)
+ printf ("%02x ", ptr[j] & 0xff);
+ printf (">");
+
+next:
ptr += ((datasz + (size - 1)) & ~ (size - 1));
- if (ptr < (ptr_end - (size * 2)))
+ if (ptr == ptr_end)
+ break;
+ else
{
if (do_wide)
printf (", ");
else
printf ("\n\t");
}
+
+ if (ptr > (ptr_end - 8))
+ {
+ printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
+ break;
+ }
}
printf ("\n");