Skip to content

Commit

Permalink
[efi] Fix Coverity warning about unintended sign extension
Browse files Browse the repository at this point in the history
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).

Signed-off-by: Michael Brown <[email protected]>
  • Loading branch information
mcb30 committed Dec 19, 2023
1 parent ded0af4 commit 15f6162
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/elf2efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 15f6162

Please sign in to comment.