diff options
Diffstat (limited to 'libelf/elf_getphdrnum.c')
-rw-r--r-- | libelf/elf_getphdrnum.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/libelf/elf_getphdrnum.c b/libelf/elf_getphdrnum.c index 63c27fb1..f2fad87a 100644 --- a/libelf/elf_getphdrnum.c +++ b/libelf/elf_getphdrnum.c @@ -80,23 +80,11 @@ __elf_getphdrnum_rdlock (elf, dst) } int -elf_getphdrnum (elf, dst) +__elf_getphdrnum_chk_rdlock (elf, dst) Elf *elf; size_t *dst; { - int result; - - if (elf == NULL) - return -1; - - if (unlikely (elf->kind != ELF_K_ELF)) - { - __libelf_seterrno (ELF_E_INVALID_HANDLE); - return -1; - } - - rwlock_rdlock (elf->lock); - result = __elf_getphdrnum_rdlock (elf, dst); + int result = __elf_getphdrnum_rdlock (elf, dst); /* Do some sanity checking to make sure phnum and phoff are consistent. */ Elf64_Off off = (elf->class == ELFCLASS32 @@ -105,14 +93,13 @@ elf_getphdrnum (elf, dst) if (unlikely (off == 0)) { *dst = 0; - goto out; + return result; } if (unlikely (off >= elf->maximum_size)) { __libelf_seterrno (ELF_E_INVALID_DATA); - result = -1; - goto out; + return -1; } /* Check for too many sections. */ @@ -121,15 +108,34 @@ elf_getphdrnum (elf, dst) if (unlikely (*dst > SIZE_MAX / phdr_size)) { __libelf_seterrno (ELF_E_INVALID_DATA); - result = -1; - goto out; + return -1; } /* Truncated file? Don't return more than can be indexed. */ if (unlikely (elf->maximum_size - off < *dst * phdr_size)) *dst = (elf->maximum_size - off) / phdr_size; -out: + return result; +} + +int +elf_getphdrnum (elf, dst) + Elf *elf; + size_t *dst; +{ + int result; + + if (elf == NULL) + return -1; + + if (unlikely (elf->kind != ELF_K_ELF)) + { + __libelf_seterrno (ELF_E_INVALID_HANDLE); + return -1; + } + + rwlock_rdlock (elf->lock); + result = __elf_getphdrnum_chk_rdlock (elf, dst); rwlock_unlock (elf->lock); return result; |