[Spice-commits] 3 commits - gtk/channel-playback.c gtk/channel-record.c gtk/spice-gtk-session.c

Christophe Fergau teuf at kemper.freedesktop.org
Wed Nov 19 04:47:10 PST 2014


 gtk/channel-playback.c  |    3 +--
 gtk/channel-record.c    |    2 +-
 gtk/spice-gtk-session.c |   30 +++++++++++++++++++++++-------
 3 files changed, 25 insertions(+), 10 deletions(-)

New commits:
commit 427a885de29bcd4196428e7747d702cd83f3aa43
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Tue Nov 18 18:10:03 2014 +0100

    Really fix SndCodec leaks in handle_{playback,record}_start
    
    The leak fix from commit 6729c341120f was actually not doing anything at
    all as it was setting c->codec to NULL before trying to free it. It was
    also not fixing the exact same leak in the record channel.
    This commit addresses these 2 issues.

diff --git a/gtk/channel-playback.c b/gtk/channel-playback.c
index 40e01ba..ae8a75d 100644
--- a/gtk/channel-playback.c
+++ b/gtk/channel-playback.c
@@ -372,10 +372,9 @@ static void playback_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
     c->last_time = start->time;
     c->is_active = TRUE;
     c->min_latency = SPICE_PLAYBACK_DEFAULT_LATENCY_MS;
-    c->codec = NULL;
+    snd_codec_destroy(&c->codec);
 
     if (c->mode != SPICE_AUDIO_DATA_MODE_RAW) {
-        snd_codec_destroy(&c->codec);
         if (snd_codec_create(&c->codec, c->mode, start->frequency, SND_CODEC_DECODE) != SND_CODEC_OK) {
             g_warning("create decoder failed");
             return;
diff --git a/gtk/channel-record.c b/gtk/channel-record.c
index 946d66f..ac71999 100644
--- a/gtk/channel-record.c
+++ b/gtk/channel-record.c
@@ -406,7 +406,7 @@ static void record_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
 
     g_return_if_fail(start->format == SPICE_AUDIO_FMT_S16);
 
-    c->codec = NULL;
+    snd_codec_destroy(&c->codec);
 
     if (c->mode != SPICE_AUDIO_DATA_MODE_RAW) {
         if (snd_codec_create(&c->codec, c->mode, start->frequency, SND_CODEC_ENCODE) != SND_CODEC_OK) {
commit 9c50ee640fe96622f4adc2b26458bc0c9b5bed3c
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Nov 17 11:41:05 2014 +0100

    Recheck clipboard size after modifying its data
    
    SpiceGtkSession::clipboard_received_cb() starts by checking if the
    clipboard is empty, or if the length of its data exceeds
    'max-clipboard-size'.
    
    Later in that function, the data is modified, and can be shortened
    (removal of trailing '\0' or of '\r' for Windows -> linux copy and
    paste), or enlarged (addition of '\r' for linux -> Windows c&p).
    
    This commit adds another check that the clipboard length is still valid
    (non-0, and not bigger than 'max-clipboard-size') after making these
    transformations.

diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
index 959b78a..701950d 100644
--- a/gtk/spice-gtk-session.c
+++ b/gtk/spice-gtk-session.c
@@ -847,6 +847,24 @@ skip_grab_clipboard:
     return TRUE;
 }
 
+static gboolean check_clipboard_size_limits(SpiceGtkSession *session,
+                                            gint clipboard_len)
+{
+    int max_clipboard;
+
+    g_object_get(session->priv->main, "max-clipboard", &max_clipboard, NULL);
+    if (max_clipboard != -1 && clipboard_len > max_clipboard) {
+        g_warning("discarded clipboard of size %d (max: %d)",
+                  clipboard_len, max_clipboard);
+        return FALSE;
+    } else if (clipboard_len <= 0) {
+        SPICE_DEBUG("discarding empty clipboard");
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 static void clipboard_received_cb(GtkClipboard *clipboard,
                                   GtkSelectionData *selection_data,
                                   gpointer user_data)
@@ -866,18 +884,12 @@ static void clipboard_received_cb(GtkClipboard *clipboard,
     gchar* name;
     GdkAtom atom;
     int selection;
-    int max_clipboard;
 
     selection = get_selection_from_clipboard(s, clipboard);
     g_return_if_fail(selection != -1);
 
-    g_object_get(s->main, "max-clipboard", &max_clipboard, NULL);
     len = gtk_selection_data_get_length(selection_data);
-    if (max_clipboard != -1 && len > max_clipboard) {
-        g_warning("discarded clipboard of size %d (max: %d)", len, max_clipboard);
-        return;
-    } else if (len <= 0) {
-        SPICE_DEBUG("discarding empty clipboard");
+    if (!check_clipboard_size_limits(self, len)) {
         return;
     } else {
         atom = gtk_selection_data_get_data_type(selection_data);
@@ -923,6 +935,10 @@ static void clipboard_received_cb(GtkClipboard *clipboard,
              */
             len = strlen((const char *)data);
         }
+        if (!check_clipboard_size_limits(self, len)) {
+            g_free(conv);
+            return;
+        }
     }
 
     spice_main_clipboard_selection_notify(s->main, selection, type,
commit 21c177c378d232137329e8c5e38658e532f64b2a
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Nov 17 11:38:46 2014 +0100

    Fix empty clipboard check
    
    SpiceGtkSession::clipboard_received_cb starts by checking if the
    length of the X selection data is not 0. However, right after this check,
    if gtk_selection_data_get_length() returned -1, it decides it got an
    empty clipboard, sets the selection length to 0, and does not return
    early.
    This commit reworks the len == 0 / len == -1 checks to make sure we
    always return early when we get no data from the clipboard.

diff --git a/gtk/spice-gtk-session.c b/gtk/spice-gtk-session.c
index 52ad597..959b78a 100644
--- a/gtk/spice-gtk-session.c
+++ b/gtk/spice-gtk-session.c
@@ -873,12 +873,12 @@ static void clipboard_received_cb(GtkClipboard *clipboard,
 
     g_object_get(s->main, "max-clipboard", &max_clipboard, NULL);
     len = gtk_selection_data_get_length(selection_data);
-    if (len == 0 || (max_clipboard != -1 && len > max_clipboard)) {
+    if (max_clipboard != -1 && len > max_clipboard) {
         g_warning("discarded clipboard of size %d (max: %d)", len, max_clipboard);
         return;
-    } else if (len == -1) {
-        SPICE_DEBUG("empty clipboard");
-        len = 0;
+    } else if (len <= 0) {
+        SPICE_DEBUG("discarding empty clipboard");
+        return;
     } else {
         atom = gtk_selection_data_get_data_type(selection_data);
         name = gdk_atom_name(atom);


More information about the Spice-commits mailing list