zdump: read_elf_phdrs: fix -Wconversion issue

`ehdr->e_phoff` has the type `Elf64_Off` and this maps to `uint64_t`, but `off_t` is signed. Let's
add a check for this.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2022-10-07 12:04:43 +00:00
committed by Jan Höppner
parent 09c413b1be
commit 25475bdf42
2 changed files with 7 additions and 1 deletions
+4 -1
View File
@@ -74,10 +74,13 @@ Elf64_Phdr *read_elf_phdrs(const struct zg_fh *fh, const Elf64_Ehdr *ehdr, unsig
return NULL;
}
if (ehdr->e_phoff > OFF_T_MAX)
ERR_EXIT("Unsupported offset");
/* Cannot wraparound since `Elf64_Half`` is `uint16_t` */
phdrs_size = sizeof(*phdrs) * phnum;
phdrs = util_malloc(phdrs_size);
zg_seek(fh, ehdr->e_phoff, ZG_CHECK);
zg_seek(fh, (off_t)ehdr->e_phoff, ZG_CHECK);
zg_read(fh, phdrs, phdrs_size, ZG_CHECK);
*phdr_count = phnum;
return phdrs;
+3
View File
@@ -16,6 +16,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
@@ -31,6 +32,8 @@
#define U32_MAX ((u32) -1)
#define U16_MAX ((u16) -1)
#define U8_MAX ((u8) -1)
#define OFF_T_MAX LONG_MAX
STATIC_ASSERT(sizeof(off_t) == sizeof(long))
/*
* IEC definitions