diff options
author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2023-04-05 12:34:15 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2023-04-28 20:30:17 +0300 |
commit | 1a07d395210cc0e9a114826e0b42106fd4336f46 (patch) | |
tree | 714e57df289aa19b77093e2f4595bced7eff5c0f /arch/sandbox/cpu | |
parent | 86daa47c84ddb67d880f304b9cb22898f2687811 (diff) | |
download | u-boot-1a07d395210cc0e9a114826e0b42106fd4336f46.tar.xz |
sandbox: fix return type of os_filesize()
Given a file ../img of size 4294967296 with GPT partition table and
partitions:
=> host bind 0 ../img
=> part list host 0
Disk host-0.blk not ready
The cause is os_filesize() returning int. File sizes must use off_t.
Correct all uses of os_filesize() too.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'arch/sandbox/cpu')
-rw-r--r-- | arch/sandbox/cpu/os.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 5e66304e2b..9e93a0fa57 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -166,7 +166,7 @@ int os_write_file(const char *fname, const void *buf, int size) return 0; } -int os_filesize(int fd) +off_t os_filesize(int fd) { off_t size; @@ -218,7 +218,7 @@ err: int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep) { void *ptr; - int size; + off_t size; int ifd; ifd = os_open(pathname, os_flags); @@ -231,6 +231,10 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep) printf("Cannot get file size of '%s'\n", pathname); return -EIO; } + if ((unsigned long long)size > (unsigned long long)SIZE_MAX) { + printf("File '%s' too large to map\n", pathname); + return -EIO; + } ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ifd, 0); if (ptr == MAP_FAILED) { |