clipboard: Check for empty string when deserializing

It's possible that nautilus_clipbaord_from_string() receives an
empty string.  When an empty string is received nautilus crashes
because g_str_equal() cannot handle the null value returned from
g_strsplit().  We could simply change g_str_equal() to g_strcmp0()
but that opens up the possibility for the for loop to give
unexpected results (it only checks for NULL starting at index=1).

Check if the results from g_strsplit()[0] == NULL and return early.
This commit is contained in:
Corey Berla 2022-07-13 13:11:36 -07:00 committed by António Fernandes
parent 0aa1b66ffa
commit f5465fdf7e

View file

@ -79,6 +79,11 @@ nautilus_clipboard_from_string (char *string)
{
lines = g_strsplit (string, "\n", 0);
if (lines[0] == NULL)
{
return clip;
}
/* Line 0 is "cut" or "copy", so uris start at line 1. */
clip->cut = g_str_equal (lines[0], "cut");
for (int i = 1; lines[i] != NULL; i++)