mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
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:
committed by
Jan Höppner
parent
09c413b1be
commit
25475bdf42
+4
-1
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user