提交 725e14e9 编写于 作者: M Markus Armbruster 提交者: Blue Swirl

loader: Fix read_targphys() to behave when read() fails

Happily passes (size_t)-1 to rom_add_blob_fixed(), which promptly dies
attempting to malloc that much.  Spotted by Coverity.

Bonus fix for ROMs larger than INT_MAX bytes: return ssize_t instead
of int.  Bug can't bite, because the only user load_aout() limits ROM
size to an int value.
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NBlue Swirl <blauwirbel@gmail.com>
上级 96d922a6
...@@ -85,11 +85,11 @@ int load_image(const char *filename, uint8_t *addr) ...@@ -85,11 +85,11 @@ int load_image(const char *filename, uint8_t *addr)
} }
/* read()-like version */ /* read()-like version */
int read_targphys(const char *name, ssize_t read_targphys(const char *name,
int fd, target_phys_addr_t dst_addr, size_t nbytes) int fd, target_phys_addr_t dst_addr, size_t nbytes)
{ {
uint8_t *buf; uint8_t *buf;
size_t did; ssize_t did;
buf = g_malloc(nbytes); buf = g_malloc(nbytes);
did = read(fd, buf, nbytes); did = read(fd, buf, nbytes);
...@@ -176,7 +176,8 @@ static void bswap_ahdr(struct exec *e) ...@@ -176,7 +176,8 @@ static void bswap_ahdr(struct exec *e)
int load_aout(const char *filename, target_phys_addr_t addr, int max_sz, int load_aout(const char *filename, target_phys_addr_t addr, int max_sz,
int bswap_needed, target_phys_addr_t target_page_size) int bswap_needed, target_phys_addr_t target_page_size)
{ {
int fd, size, ret; int fd;
ssize_t size, ret;
struct exec e; struct exec e;
uint32_t magic; uint32_t magic;
......
...@@ -14,7 +14,7 @@ int load_aout(const char *filename, target_phys_addr_t addr, int max_sz, ...@@ -14,7 +14,7 @@ int load_aout(const char *filename, target_phys_addr_t addr, int max_sz,
int load_uimage(const char *filename, target_phys_addr_t *ep, int load_uimage(const char *filename, target_phys_addr_t *ep,
target_phys_addr_t *loadaddr, int *is_linux); target_phys_addr_t *loadaddr, int *is_linux);
int read_targphys(const char *name, ssize_t read_targphys(const char *name,
int fd, target_phys_addr_t dst_addr, size_t nbytes); int fd, target_phys_addr_t dst_addr, size_t nbytes);
void pstrcpy_targphys(const char *name, void pstrcpy_targphys(const char *name,
target_phys_addr_t dest, int buf_size, target_phys_addr_t dest, int buf_size,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册