[gnome-shell/wip/carlosg/nul-after-pasted-text: 12/12] st-clipboard: Add trailing 0 to pasted text



commit 8d9cae45f9a44b47627449c674056767add07af8
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Sep 9 17:43:17 2019 +0200

    st-clipboard: Add trailing 0 to pasted text
    
    We translate the raw stream content far too directly into a char*,
    it notably forgets that the stream does not have nul-ended data,
    this means we are potentially adding garbage after the pasted content.
    
    Tentatively fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1570

 src/st/st-clipboard.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/src/st/st-clipboard.c b/src/st/st-clipboard.c
index bdd4104f37..b2d8e7f940 100644
--- a/src/st/st-clipboard.c
+++ b/src/st/st-clipboard.c
@@ -128,14 +128,22 @@ transfer_cb (MetaSelection *selection,
              GAsyncResult  *res,
              TransferData  *data)
 {
-  const gchar *text = NULL;
+  gchar *text = NULL;
 
   if (meta_selection_transfer_finish (selection, res, NULL))
-    text = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->stream));
+    {
+      gsize data_size;
+
+      data_size =
+        g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->stream));
+      text = g_new0 (char, data_size + 1);
+      memcpy (text, g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->stream)), data_size);
+    }
 
   data->callback (data->clipboard, text, data->user_data);
   g_object_unref (data->stream);
   g_free (data);
+  g_free (text);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]