[Spice-commits] 2 commits - src/spice-channel.c

Marc-André Lureau elmarco at kemper.freedesktop.org
Thu Aug 17 13:27:12 UTC 2017


 src/spice-channel.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

New commits:
commit eb6206d6edc696343e1e5d38bada50ef16a783be
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Thu Aug 10 19:54:55 2017 +0200

    channel: don't call memcpy with NULL dest
    
    If ncaps == 0, the array will be NULL after set_size().
    
    Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 0dc46c3..21f868d 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1891,6 +1891,9 @@ static void store_caps(const uint8_t *caps_src, uint32_t ncaps,
     guint i;
 
     g_array_set_size(caps_dst, ncaps);
+    if (ncaps == 0)
+        return;
+
     caps = &g_array_index(caps_dst, uint32_t, 0);
     memcpy(caps, caps_src, ncaps * sizeof(uint32_t));
 
commit 89a17ad3ff4df84aa59c9e05af90bcb83653e8fd
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Thu Aug 10 19:53:07 2017 +0200

    channel: pass the size to store_caps
    
    Move g_array_set_size() there.
    
    Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 8ff2f28..0dc46c3 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1884,14 +1884,17 @@ cleanup:
 #endif /* HAVE_SASL */
 
 /* coroutine context */
-static void store_caps(const uint8_t *caps_src, const GArray *caps_dst)
+static void store_caps(const uint8_t *caps_src, uint32_t ncaps,
+                       GArray *caps_dst)
 {
     uint32_t *caps;
     guint i;
 
+    g_array_set_size(caps_dst, ncaps);
     caps = &g_array_index(caps_dst, uint32_t, 0);
-    memcpy(caps, caps_src, caps_dst->len * sizeof(uint32_t));
-    for (i = 0; i < caps_dst->len; i++, caps++) {
+    memcpy(caps, caps_src, ncaps * sizeof(uint32_t));
+
+    for (i = 0; i < ncaps; i++, caps++) {
         *caps = GUINT32_FROM_LE(*caps);
         SPICE_DEBUG("\t%u:0x%X", i, *caps);
     }
@@ -1944,14 +1947,12 @@ static gboolean spice_channel_recv_link_msg(SpiceChannel *channel)
     /* g_return_if_fail(c->peer_msg + c->peer_msg->caps_offset * sizeof(uint32_t) > c->peer_msg + c->peer_hdr.size); */
 
     caps_src = (uint8_t *)c->peer_msg + GUINT32_FROM_LE(c->peer_msg->caps_offset);
-    g_array_set_size(c->remote_common_caps, num_common_caps);
     CHANNEL_DEBUG(channel, "got remote common caps:");
-    store_caps(caps_src, c->remote_common_caps);
+    store_caps(caps_src, num_common_caps, c->remote_common_caps);
 
     caps_src += num_common_caps * sizeof(uint32_t);
-    g_array_set_size(c->remote_caps, num_channel_caps);
     CHANNEL_DEBUG(channel, "got remote channel caps:");
-    store_caps(caps_src, c->remote_caps);
+    store_caps(caps_src, num_channel_caps, c->remote_caps);
 
     if (!spice_channel_test_common_capability(channel,
             SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION)) {


More information about the Spice-commits mailing list