summaryrefslogtreecommitdiffstats
path: root/libelf/gelf_getphdr.c
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2010-01-07 19:41:04 -0800
committerRoland McGrath <[email protected]>2010-01-07 19:43:42 -0800
commit6fd3cd104adf4107aa64e1c1e84028b4ea0b3296 (patch)
tree6d42f1017e802ccf94abbe5af598eec8b2600166 /libelf/gelf_getphdr.c
parent7452e1953a4a4e70af3fb472e609e89776031e53 (diff)
Add elf_getphdrnum, support >65536 phdrs.
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;