From 77e205a52856adffdd5db70449a8604aa9f66e74 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Sat, 15 Nov 2014 18:06:41 +0800 Subject: mips_mipssim: fix use-after-free for filename May pass freed pointer filename as an argument to error_report. Signed-off-by: Gonglei Signed-off-by: Paolo Bonzini --- hw/mips/mips_mipssim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c index 7ea0b9a..5d44c3f 100644 --- a/hw/mips/mips_mipssim.c +++ b/hw/mips/mips_mipssim.c @@ -197,7 +197,7 @@ mips_mipssim_init(MachineState *machine) !kernel_filename && !qtest_enabled()) { /* Bail out if we have neither a kernel image nor boot vector code. */ error_report("Could not load MIPS bios '%s', and no " - "-kernel argument was specified", filename); + "-kernel argument was specified", bios_name); exit(1); } else { /* We have a boot vector start address. */ -- cgit v1.1 From ddd2eab72fbd383a56f439bf278c6d647abd4f54 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Sat, 15 Nov 2014 18:06:43 +0800 Subject: loader: fix NEGATIVE_RETURNS 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 Signed-off-by: Paolo Bonzini --- hw/core/loader.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'hw') 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); -- cgit v1.1 From 720fdd6fa92df9041316e94816ab7e56abaed4e9 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Sat, 15 Nov 2014 18:06:44 +0800 Subject: nvme: remove superfluous check Operands don't affect result (CONSTANT_EXPRESSION_RESULT) ((n->bar.aqa >> AQA_ASQS_SHIFT) & AQA_ASQS_MASK) > 4095 is always false regardless of the values of its operands. This occurs as the logical second operand of '||'. Signed-off-by: Gonglei Signed-off-by: Paolo Bonzini --- hw/block/nvme.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/block/nvme.c b/hw/block/nvme.c index b6263dc..1327658 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -583,8 +583,7 @@ static int nvme_start_ctrl(NvmeCtrl *n) NVME_CC_IOCQES(n->bar.cc) > NVME_CTRL_CQES_MAX(n->id_ctrl.cqes) || NVME_CC_IOSQES(n->bar.cc) < NVME_CTRL_SQES_MIN(n->id_ctrl.sqes) || NVME_CC_IOSQES(n->bar.cc) > NVME_CTRL_SQES_MAX(n->id_ctrl.sqes) || - !NVME_AQA_ASQS(n->bar.aqa) || NVME_AQA_ASQS(n->bar.aqa) > 4095 || - !NVME_AQA_ACQS(n->bar.aqa) || NVME_AQA_ACQS(n->bar.aqa) > 4095) { + !NVME_AQA_ASQS(n->bar.aqa) || !NVME_AQA_ACQS(n->bar.aqa)) { return -1; } -- cgit v1.1 From 0e8b439ae57ee3c46fb95e1775ea038d34496346 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Sat, 15 Nov 2014 18:06:47 +0800 Subject: shpc: fix error propaagation Signed-off-by: Gonglei Signed-off-by: Paolo Bonzini --- hw/pci/shpc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 65b2f51..9a39060 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -559,8 +559,9 @@ void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev, uint8_t led; int slot; - shpc_device_hotplug_common(PCI_DEVICE(dev), &slot, shpc, errp); + shpc_device_hotplug_common(PCI_DEVICE(dev), &slot, shpc, &local_err); if (local_err) { + error_propagate(errp, local_err); return; } -- cgit v1.1 From a9be76576e375a994bbcea0a5eb2a3852969de0e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 17 Nov 2014 11:57:23 +0100 Subject: hcd-musb: fix dereference null return value usb_ep_get and usb_handle_packet can deal with a NULL device, but we have to avoid dereferencing NULL pointers when building the id. Thanks to Gonglei for an initial stab at fixing this. Signed-off-by: Paolo Bonzini --- hw/usb/hcd-musb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/usb/hcd-musb.c b/hw/usb/hcd-musb.c index 66bc61a..40809f6 100644 --- a/hw/usb/hcd-musb.c +++ b/hw/usb/hcd-musb.c @@ -608,6 +608,7 @@ static void musb_packet(MUSBState *s, MUSBEndPoint *ep, USBDevice *dev; USBEndpoint *uep; int idx = epnum && dir; + int id; int ttype; /* ep->type[0,1] contains: @@ -625,8 +626,11 @@ static void musb_packet(MUSBState *s, MUSBEndPoint *ep, /* A wild guess on the FADDR semantics... */ dev = usb_find_device(&s->port, ep->faddr[idx]); uep = usb_ep_get(dev, pid, ep->type[idx] & 0xf); - usb_packet_setup(&ep->packey[dir].p, pid, uep, 0, - (dev->addr << 16) | (uep->nr << 8) | pid, false, true); + id = pid; + if (uep) { + id |= (dev->addr << 16) | (uep->nr << 8); + } + usb_packet_setup(&ep->packey[dir].p, pid, uep, 0, id, false, true); usb_packet_addbuf(&ep->packey[dir].p, ep->buf[idx], len); ep->packey[dir].ep = ep; ep->packey[dir].dir = dir; -- cgit v1.1