diff mbox series

[v3,10/25] usb-redir: Verify usbredirparser_write get called with positive count

Message ID 20190220010232.18731-11-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series chardev: Convert qemu_chr_write() to take a size_t argument | expand

Commit Message

Philippe Mathieu-Daudé Feb. 20, 2019, 1:02 a.m. UTC
The usbredirparser_write handler should never be called with a negative
size payload, return an error if this is not the case.
Now that we are sure the 'count' value is positive, make it obvious by
casting it to a size_t.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/usb/redirect.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Gerd Hoffmann Feb. 20, 2019, 7:32 a.m. UTC | #1
On Wed, Feb 20, 2019 at 02:02:17AM +0100, Philippe Mathieu-Daudé wrote:
> The usbredirparser_write handler should never be called with a negative
> size payload, return an error if this is not the case.
> Now that we are sure the 'count' value is positive, make it obvious by
> casting it to a size_t.

Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
diff mbox series

Patch

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 18a42d1938..131eae2e7e 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -285,7 +285,11 @@  static int usbredir_write(void *priv, uint8_t *data, int count)
         return 0;
     }
 
-    r = qemu_chr_fe_write(&dev->cs, data, count);
+    if (count < 0) {
+        ERROR("Illegal write count: %i\n", count);
+        return 0;
+    }
+    r = qemu_chr_fe_write(&dev->cs, data, (size_t)count);
     if (r < count) {
         if (!dev->watch) {
             dev->watch = qemu_chr_fe_add_watch(&dev->cs, G_IO_OUT | G_IO_HUP,