summaryrefslogtreecommitdiffstats
path: root/libelf/gelf_getphdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'libelf/gelf_getphdr.c')
-rw-r--r--libelf/gelf_getphdr.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libelf/gelf_getphdr.c b/libelf/gelf_getphdr.c
index 66cd143d..7b04b399 100644
--- a/libelf/gelf_getphdr.c
+++ b/libelf/gelf_getphdr.c
@@ -1,5 +1,5 @@
/* Return program header table entry.
- Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 1998-2010 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <[email protected]>, 1998.
@@ -100,7 +100,11 @@ gelf_getphdr (elf, ndx, dst)
}
/* Test whether the index is ok. */
- if (ndx >= elf->state.elf32.ehdr->e_phnum)
+ size_t phnum;
+ if (ndx >= elf->state.elf32.ehdr->e_phnum
+ && (elf->state.elf32.ehdr->e_phnum != PN_XNUM
+ || __elf_getphdrnum_rdlock (elf, &phnum) != 0
+ || (size_t) ndx >= phnum))
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;
@@ -138,7 +142,11 @@ gelf_getphdr (elf, ndx, dst)
}
/* Test whether the index is ok. */
- if (ndx >= elf->state.elf64.ehdr->e_phnum)
+ size_t phnum;
+ if (ndx >= elf->state.elf64.ehdr->e_phnum
+ && (elf->state.elf64.ehdr->e_phnum != PN_XNUM
+ || __elf_getphdrnum_rdlock (elf, &phnum) != 0
+ || (size_t) ndx >= phnum))
{
__libelf_seterrno (ELF_E_INVALID_INDEX);
goto out;