summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2023-12-19 17:56:34 +0100
committerMichael Brown2023-12-19 17:56:34 +0100
commit3fc1b407d204e950a41c567e84f4c4f079cc052e (patch)
treea8397c3dcb94c2b16dd9221ead430c1302e52eb7
parent[efi] Add relocation types generated by clang (diff)
downloadipxe-3fc1b407d204e950a41c567e84f4c4f079cc052e.tar.gz
ipxe-3fc1b407d204e950a41c567e84f4c4f079cc052e.tar.xz
ipxe-3fc1b407d204e950a41c567e84f4c4f079cc052e.zip
[efi] Fix Coverity warning about unintended sign extension
The result of multiplying a uint16_t by another uint16_t will be a signed int. Comparing this against a size_t will perform an unwanted sign extension. Fix by explicitly casting e_phnum to an unsigned int, thereby matching the data type used for the loop index variable (and avoiding the unwanted sign extension). This mirrors wimboot commit 15f6162 ("[efi] Fix Coverity warning about unintended sign extension"). Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/util/elf2efi.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index 3bf6cbf9..29e4f24a 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -440,8 +440,8 @@ static void read_elf_file ( const char *name, struct elf_file *elf ) {
/* Check program headers */
if ( ( elf->len < ehdr->e_phoff ) ||
- ( ( elf->len - ehdr->e_phoff ) < ( ehdr->e_phnum *
- ehdr->e_phentsize ) ) ) {
+ ( ( elf->len - ehdr->e_phoff ) <
+ ( ( ( unsigned int ) ehdr->e_phnum ) * ehdr->e_phentsize ) ) ) {
eprintf ( "ELF program headers outside file in %s\n", name );
exit ( 1 );
}