summaryrefslogtreecommitdiffstats
path: root/libelf/elf_getshdrstrndx.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2014-12-19 00:06:26 +0100
committerMark Wielaard <[email protected]>2014-12-19 00:06:26 +0100
commitbd0434b61e0317718eb159fe7b5dc9ea870a0b79 (patch)
tree825a373c2233a59b5156b219013e32f8f241aacc /libelf/elf_getshdrstrndx.c
parente18bf66ce8070f96195880e83a50c9d98006b832 (diff)
parent898ed261444cdd817c2d9b3656209a291eb5e807 (diff)
Merge branch 'master' into portable
Diffstat (limited to 'libelf/elf_getshdrstrndx.c')
-rw-r--r--libelf/elf_getshdrstrndx.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/libelf/elf_getshdrstrndx.c b/libelf/elf_getshdrstrndx.c
index 1dbed4c8..6f8d66e8 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;