[Spice-commits] src/channel-usbredir.c

Victor Toso de Carvalho victortoso at kemper.freedesktop.org
Thu Mar 1 08:57:17 UTC 2018


 src/channel-usbredir.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 71bab22cdc437f7018339d524bb1d774b6ee2eea
Author: Victor Toso <me at victortoso.com>
Date:   Wed Feb 28 13:38:45 2018 +0100

    channel-usbredir: avoid calling memcpy() will NULL src
    
    Code built with address sanitizer has runtime error:
     > channel-usbredir.c:642:5: runtime error: null pointer passed
     > as argument 2, which is declared to never be null
    
    Signed-off-by: Victor Toso <victortoso at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 1f791bc..a19df17 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -635,11 +635,11 @@ static int usbredir_read_callback(void *user_data, uint8_t *data, int count)
     SpiceUsbredirChannel *channel = user_data;
     SpiceUsbredirChannelPrivate *priv = channel->priv;
 
-    if (priv->read_buf_size < count) {
-        count = priv->read_buf_size;
-    }
+    count = MIN(priv->read_buf_size, count);
 
-    memcpy(data, priv->read_buf, count);
+    if (count != 0) {
+        memcpy(data, priv->read_buf, count);
+    }
 
     priv->read_buf_size -= count;
     if (priv->read_buf_size) {


More information about the Spice-commits mailing list