From f5465fdf7ed890a8b7d6c21b6dfdead0a061f0e7 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Wed, 13 Jul 2022 13:11:36 -0700 Subject: [PATCH] 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. --- src/nautilus-clipboard.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/nautilus-clipboard.c b/src/nautilus-clipboard.c index 03bb7263f..afa0d58f1 100644 --- a/src/nautilus-clipboard.c +++ b/src/nautilus-clipboard.c @@ -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++)