[nautilus] clipboard: Check for empty string when deserializing



commit f5465fdf7ed890a8b7d6c21b6dfdead0a061f0e7
Author: Corey Berla <corey berla me>
Date:   Wed Jul 13 13:11:36 2022 -0700

    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++)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]