From: Mark Wielaard Date: Sun, 16 Nov 2014 23:42:53 +0000 (+0100) Subject: libelf: elf_getshdrstrndx cannot use SHN_XINDEX without section headers. X-Git-Tag: elfutils-0.161~82 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=babcdeff28bdf1d5ce26c8aa35fea420921f4ba7;p=thirdparty%2Felfutils.git libelf: elf_getshdrstrndx cannot use SHN_XINDEX without section headers. Signed-off-by: Mark Wielaard --- diff --git a/libelf/ChangeLog b/libelf/ChangeLog index ef5da43d4..633a8923f 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2014-11-16 Mark Wielaard + + * elf_getshdrstrndx.c: Check there are section headers before + handling SHN_XINDEX. + 2014-11-16 Mark Wielaard * elf32_getphdr.c (getphdr_wrlock): Check e_phoff isn't zero. diff --git a/libelf/elf_getshdrstrndx.c b/libelf/elf_getshdrstrndx.c index 1dbed4c84..6f8d66e80 100644 --- a/libelf/elf_getshdrstrndx.c +++ b/libelf/elf_getshdrstrndx.c @@ -92,6 +92,13 @@ elf_getshdrstrndx (elf, dst) if (elf->class == ELFCLASS32) { size_t offset; + if (unlikely (elf->state.elf32.scns.cnt == 0)) + { + /* Cannot use SHN_XINDEX without section headers. */ + __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); + result = -1; + goto out; + } if (elf->state.elf32.scns.data[0].shdr.e32 != NULL) { @@ -146,6 +153,14 @@ elf_getshdrstrndx (elf, dst) } else { + if (unlikely (elf->state.elf64.scns.cnt == 0)) + { + /* Cannot use SHN_XINDEX without section headers. */ + __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); + result = -1; + goto out; + } + if (elf->state.elf64.scns.data[0].shdr.e64 != NULL) { num = elf->state.elf64.scns.data[0].shdr.e64->sh_link;