]> xenbits.xensource.com Git - osstest/qemu.git/commitdiff
usb: mtp: fix possible buffer overflow
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 25 Apr 2014 10:05:15 +0000 (12:05 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Mon, 5 May 2014 10:57:58 +0000 (12:57 +0200)
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/usb/dev-mtp.c

index b6eaeae17a4bcac1507f0622de25b3ca5b05b111..62428d8e7b31dff428849d6e00e25d46797264c8 100644 (file)
@@ -998,6 +998,14 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)
             cmd.argc = (le32_to_cpu(container.length) - sizeof(container))
                 / sizeof(uint32_t);
             cmd.trans = le32_to_cpu(container.trans);
+            if (cmd.argc > ARRAY_SIZE(cmd.argv)) {
+                cmd.argc = ARRAY_SIZE(cmd.argv);
+            }
+            if (p->iov.size < sizeof(container) + cmd.argc * sizeof(uint32_t)) {
+                trace_usb_mtp_stall(s->dev.addr, "packet too small");
+                p->status = USB_RET_STALL;
+                return;
+            }
             usb_packet_copy(p, &params, cmd.argc * sizeof(uint32_t));
             for (i = 0; i < cmd.argc; i++) {
                 cmd.argv[i] = le32_to_cpu(params[i]);