This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 2/2] [nto] Improve ABI sniffing.
- From: Pedro Alves <palves at redhat dot com>
- To: Aleksandar Ristovski <aristovski at qnx dot com>, gdb-patches at sourceware dot org
- Date: Wed, 21 Oct 2015 14:47:35 +0100
- Subject: Re: [PATCH 2/2] [nto] Improve ABI sniffing.
- Authentication-results: sourceware.org; auth=none
- References: <5621218D dot 6070801 at redhat dot com> <1445364649-12175-1-git-send-email-aristovski at qnx dot com> <1445364649-12175-3-git-send-email-aristovski at qnx dot com> <56275FB2 dot 3050509 at redhat dot com> <5627944D dot 3050900 at qnx dot com>
On 10/21/2015 02:34 PM, Aleksandar Ristovski wrote:
> +static void
> +nto_sniff_abi_note_section (bfd *abfd, asection *sect, void *obj)
> +{
> + const char *sectname;
> + unsigned int sectsize;
> + /* Buffer holding the section contents. */
> + char *note;
> + unsigned int namelen;
> + const char *name;
> +
> + sectname = bfd_get_section_name (abfd, sect);
> + sectsize = bfd_section_size (abfd, sect);
> +
> + if (sectsize > 128)
> + sectsize = 128;
> +
> + if (sectname != NULL && strstr (sectname, QNX_INFO_SECT_NAME) != NULL)
> + *(enum gdb_osabi *) obj = GDB_OSABI_QNXNTO;
> +
> + if (sectname != NULL && strstr (sectname, "note") != NULL)
This can be "else if".
> + {
> + const unsigned sizeof_Elf_Nhdr = 12;
> +
> + note = XNEWVEC (char, sectsize);
> + bfd_get_section_contents (abfd, sect, note, 0, sectsize);
> + namelen = (unsigned int) bfd_h_get_32 (abfd, note);
You also need to check that the section's size
is enough to contain 'namelen', _before_ extracting it, otherwise
you may be reading garbage.
> + name = note + sizeof_Elf_Nhdr;
> + if (sectsize < namelen + sizeof_Elf_Nhdr
> + || namelen > sizeof (QNX_NOTE_NAME) + 1)
> + {
> + /* Can not be QNX note. */
> + XDELETEVEC (note);
> + return;
Thanks,
Pedro Alves