diff options
author | Benjamin Otte <otte@redhat.com> | 2021-04-26 20:57:55 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2021-04-26 21:32:57 +0200 |
commit | f34e3c573ba1e18a52f5007d85a8bfc27c2e4f90 (patch) | |
tree | 5a322d1ee35c1b58f320989fc41b169cc49a22b5 | |
parent | 5710df685b0af9b7dd306dfba6c7e174e428950e (diff) | |
download | gtk+-f34e3c573ba1e18a52f5007d85a8bfc27c2e4f90.tar.gz |
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
-rw-r--r-- | gdk/gdkcontentdeserializer.c | 15 |
1 files 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, |