From ca9ebad05c346ee7fb96d099623913d9e9a4581a Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 23:24:17 +0000 Subject: Apply patch 0014-clipboard-Prevent-crash-when-selection-data-is-empty.patch patch_name: 0014-clipboard-Prevent-crash-when-selection-data-is-empty.patch present_in_specfile: true location_in_specfile: 14 --- diff --git a/src/nautilus-clipboard.c b/src/nautilus-clipboard.c index 752ff13..2a77cf2 100644 --- a/src/nautilus-clipboard.c +++ b/src/nautilus-clipboard.c @@ -42,23 +42,29 @@ typedef struct static GList * convert_selection_data_to_str_list (const gchar *data) { - int i; + g_auto (GStrv) lines; + guint number_of_lines; GList *result; - size_t number_of_lines; - gchar **lines; lines = g_strsplit (data, "\n", 0); - result = NULL; number_of_lines = g_strv_length (lines); + if (number_of_lines == 0) + { + /* An empty string will result in g_strsplit() returning an empty + * array, so, naturally, 0 - 1 = UINT32_MAX and we read all sorts + * of invalid memory. + */ + return NULL; + } + result = NULL; + /* Also, this skips the last line, since it would be an * empty string from the split */ - for (i = 0; i < number_of_lines - 1; i++) + for (guint i = 0; i < number_of_lines - 1; i++) { result = g_list_prepend (result, g_strdup (lines[i])); } - g_strfreev (lines); - return g_list_reverse (result); }