[glib: 1/3] glocalfile: Check g_stat() return value




commit 24b5d86d4a36a690ff19908bf930a75921e95a49
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Dec 3 14:17:55 2020 +0000

    glocalfile: Check g_stat() return value
    
    There were a couple of places where the return value wasn’t checked, and
    hence failure could not be noticed.
    
    Coverity CIDs: #1159435, #1159426
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/glocalfile.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index a87de9cc4..15738d8b8 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -1824,6 +1824,7 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
 {
   static gsize home_dev_set = 0;
   static dev_t home_dev;
+  static gboolean home_dev_valid = FALSE;
   char *topdir, *globaldir, *trashdir, *tmpname;
   uid_t uid;
   char uid_str[32];
@@ -1834,13 +1835,23 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
     {
       GStatBuf home_stat;
 
-      g_stat (g_get_home_dir (), &home_stat);
-      home_dev = home_stat.st_dev;
+      if (g_stat (g_get_home_dir (), &home_stat) == 0)
+        {
+          home_dev = home_stat.st_dev;
+          home_dev_valid = TRUE;
+        }
+      else
+        {
+          home_dev_valid = FALSE;
+        }
+
       g_once_init_leave (&home_dev_set, 1);
     }
 
   /* Assume we can trash to the home */
-  if (dir_dev == home_dev)
+  if (!home_dev_valid)
+    return FALSE;
+  else if (dir_dev == home_dev)
     return TRUE;
 
   topdir = find_mountpoint_for (dirname, dir_dev, TRUE);
@@ -1972,7 +1983,15 @@ g_local_file_trash (GFile         *file,
     }
     
   homedir = g_get_home_dir ();
-  g_stat (homedir, &home_stat);
+  if (g_stat (homedir, &home_stat) != 0)
+    {
+      errsv = errno;
+
+      g_set_io_error (error,
+                      _("Error trashing file %s: %s"),
+                      file, errsv);
+      return FALSE;
+    }
 
   is_homedir_trash = FALSE;
   trashdir = NULL;


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