From 1af445342875b7dfd28a64a2cb71196ddfa14d9f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 25 Feb 2021 15:01:21 -0800 Subject: [PATCH] fix wrong cast The original code which worked was size_t(A + B * C). size_t(A + B) breaks it. A + size_t(B * C) is correct. Signed-off-by: Rosen Penev --- src/patchelf.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index 50eb13a..287fea8 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -397,13 +397,13 @@ ElfFile::ElfFile(FileContents fileContents) if (rdi(hdr->e_type) != ET_EXEC && rdi(hdr->e_type) != ET_DYN) error("wrong ELF type"); - if (size_t(rdi(hdr->e_phoff) + rdi(hdr->e_phnum)) * rdi(hdr->e_phentsize) > fileContents->size()) + if (rdi(hdr->e_phoff) + size_t(rdi(hdr->e_phnum) * rdi(hdr->e_phentsize)) > fileContents->size()) error("program header table out of bounds"); if (rdi(hdr->e_shnum) == 0) error("no section headers. The input file is probably a statically linked, self-decompressing binary"); - if (size_t(rdi(hdr->e_shoff) + rdi(hdr->e_shnum)) * rdi(hdr->e_shentsize) > fileContents->size()) + if (rdi(hdr->e_shoff) + size_t(rdi(hdr->e_shnum) * rdi(hdr->e_shentsize)) > fileContents->size()) error("section header table out of bounds"); if (rdi(hdr->e_phentsize) != sizeof(Elf_Phdr))