diff mbox

[6/8] libelf: loop safety cleanup: Remove obsolete check in elf_shdr_count

Message ID 1481298289-13546-7-git-send-email-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Jackson Dec. 9, 2016, 3:44 p.m. UTC
All the loops which might go out of control, due to excessive shdrs,
have been decorated with elf_iter_ok.  So there is no need for this
explicit (and rather crude) check.

(Anyway, the count was a 16-bit field, so the check was redundant.)

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 xen/common/libelf/libelf-tools.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

Comments

Jan Beulich Dec. 12, 2016, 3:41 p.m. UTC | #1
>>> On 09.12.16 at 16:44, <ian.jackson@eu.citrix.com> wrote:
> All the loops which might go out of control, due to excessive shdrs,
> have been decorated with elf_iter_ok.  So there is no need for this
> explicit (and rather crude) check.
> 
> (Anyway, the count was a 16-bit field, so the check was redundant.)
> 
> Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
diff mbox

Patch

diff --git a/xen/common/libelf/libelf-tools.c b/xen/common/libelf/libelf-tools.c
index 7fa5963..b799b56 100644
--- a/xen/common/libelf/libelf-tools.c
+++ b/xen/common/libelf/libelf-tools.c
@@ -131,17 +131,7 @@  uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr)
 
 unsigned elf_shdr_count(struct elf_binary *elf)
 {
-    unsigned count = elf_uval(elf, elf->ehdr, e_shnum);
-    uint64_t max = elf->size / sizeof(Elf32_Shdr);
-
-    if ( max > UINT_MAX )
-        max = UINT_MAX;
-    if ( count > max )
-    {
-        elf_mark_broken(elf, "far too many section headers");
-        count = max;
-    }
-    return count;
+    return elf_uval(elf, elf->ehdr, e_shnum);
 }
 
 unsigned elf_phdr_count(struct elf_binary *elf)