diff options
author | Corey Berla <corey@berla.me> | 2022-07-13 13:11:36 -0700 |
---|---|---|
committer | António Fernandes <antoniojpfernandes@gmail.com> | 2022-07-15 07:00:12 +0000 |
commit | f5465fdf7ed890a8b7d6c21b6dfdead0a061f0e7 (patch) | |
tree | c3722daf8950e04b07774ba8d7255186653d5da1 | |
parent | 0aa1b66ffa07060bb7c2dae14978a7f71e156626 (diff) | |
download | nautilus-f5465fdf7ed890a8b7d6c21b6dfdead0a061f0e7.tar.gz |
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.
-rw-r--r-- | src/nautilus-clipboard.c | 5 |
1 files changed, 5 insertions, 0 deletions
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++) |