[gtk/gtk-4-2: 74/91] clipboard: Make sure G_TYPE_STRING is nul-terminated
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk-4-2: 74/91] clipboard: Make sure G_TYPE_STRING is nul-terminated
- Date: Tue, 4 May 2021 02:05:42 +0000 (UTC)
commit 0fe3a261220973306311659d0edf800af6a1f16b
Author: Benjamin Otte <otte redhat com>
Date: Mon Apr 26 20:57:55 2021 +0200
clipboard: Make sure G_TYPE_STRING is nul-terminated
When reading text, we need to check we terminate the G_TYPE_STRING
string with a null byte, because the clipboard does not guarantee one.
So just append a \0 to the stream.
Fixes #3899
gdk/gdkcontentdeserializer.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/gdk/gdkcontentdeserializer.c b/gdk/gdkcontentdeserializer.c
index 42f77c0078..e03df87d0f 100644
--- a/gdk/gdkcontentdeserializer.c
+++ b/gdk/gdkcontentdeserializer.c
@@ -672,9 +672,18 @@ string_deserializer_finish (GObject *source,
}
else
{
+ GOutputStream *mem_stream = g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (stream));
+
+ /* write a terminating NULL byte */
+ if (g_output_stream_write (mem_stream, "", 1, NULL, &error) < 0 ||
+ !g_output_stream_close (mem_stream, NULL, &error))
+ {
+ gdk_content_deserializer_return_error (deserializer, error);
+ return;
+ }
+
g_value_take_string (gdk_content_deserializer_get_value (deserializer),
- g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (
- g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (stream)))));
+ g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (mem_stream)));
}
gdk_content_deserializer_return_success (deserializer);
}
@@ -703,7 +712,7 @@ string_deserializer (GdkContentDeserializer *deserializer)
g_output_stream_splice_async (filter,
gdk_content_deserializer_get_input_stream (deserializer),
- G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
gdk_content_deserializer_get_priority (deserializer),
gdk_content_deserializer_get_cancellable (deserializer),
string_deserializer_finish,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]