[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/9] loader: fix NEGATIVE_RETURNS
From: |
arei.gonglei |
Subject: |
[Qemu-devel] [PATCH 4/9] loader: fix NEGATIVE_RETURNS |
Date: |
Sat, 15 Nov 2014 18:06:43 +0800 |
From: Gonglei <address@hidden>
lseek will return -1 on error, g_malloc0(size) and read(,,size)
paramenters cannot be negative. We should add a check for return
value of lseek().
Signed-off-by: Gonglei <address@hidden>
---
hw/core/loader.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index bbe6eb3..fc15535 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -80,6 +80,13 @@ int load_image(const char *filename, uint8_t *addr)
if (fd < 0)
return -1;
size = lseek(fd, 0, SEEK_END);
+ if (size == -1) {
+ fprintf(stderr, "file %-20s: get size error: %s\n",
+ filename, strerror(errno));
+ close(fd);
+ return -1;
+ }
+
lseek(fd, 0, SEEK_SET);
if (read(fd, addr, size) != size) {
close(fd);
@@ -748,6 +755,12 @@ int rom_add_file(const char *file, const char *fw_dir,
}
rom->addr = addr;
rom->romsize = lseek(fd, 0, SEEK_END);
+ if (rom->romsize == -1) {
+ fprintf(stderr, "rom: file %-20s: get size error: %s\n",
+ rom->name, strerror(errno));
+ goto err;
+ }
+
rom->datasize = rom->romsize;
rom->data = g_malloc0(rom->datasize);
lseek(fd, 0, SEEK_SET);
--
1.7.12.4
- [Qemu-devel] [PATCH 0/9] Fix Coverity warning reports, arei.gonglei, 2014/11/15
- [Qemu-devel] [PATCH 7/9] qemu-char: fix MISSING_COMMA, arei.gonglei, 2014/11/15
- [Qemu-devel] [PATCH 3/9] qga: fix false negative argument passing, arei.gonglei, 2014/11/15
- [Qemu-devel] [PATCH 6/9] acl: fix memory leak, arei.gonglei, 2014/11/15
- [Qemu-devel] [PATCH 5/9] nvme: remove superfluous check, arei.gonglei, 2014/11/15
- [Qemu-devel] [PATCH 4/9] loader: fix NEGATIVE_RETURNS,
arei.gonglei <=
- [Qemu-devel] [PATCH 1/9] l2tpv3: fix fd leak, arei.gonglei, 2014/11/15
- [Qemu-devel] [PATCH 2/9] mips_mipssim: fix use-after-free for filename, arei.gonglei, 2014/11/15
- [Qemu-devel] [PATCH 9/9] hcd-musb: fix dereference null return value, arei.gonglei, 2014/11/15