[libdazzle] reaper: add additional check for symlinks



commit 2f127cfbe4c6c9ce59c98ece1524bf5fec026b2b
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 24 23:34:55 2018 -0800

    reaper: add additional check for symlinks
    
    This uses the g_file_info_is_symlink() helper with
    G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK. It helps us protect just
    a little bit more against symlinks.

 src/files/dzl-directory-reaper.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
---
diff --git a/src/files/dzl-directory-reaper.c b/src/files/dzl-directory-reaper.c
index d563be4..2bf2b20 100644
--- a/src/files/dzl-directory-reaper.c
+++ b/src/files/dzl-directory-reaper.c
@@ -168,6 +168,7 @@ remove_directory_with_children (GFile         *file,
   g_debug ("Removing uri recursively \"%s\"", uri);
 
   enumerator = g_file_enumerate_children (file,
+                                          G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK","
                                           G_FILE_ATTRIBUTE_STANDARD_NAME","
                                           G_FILE_ATTRIBUTE_STANDARD_TYPE","
                                           G_FILE_ATTRIBUTE_TIME_MODIFIED,
@@ -190,8 +191,9 @@ remove_directory_with_children (GFile         *file,
     {
       g_autoptr(GFileInfo) info = infoptr;
       g_autoptr(GFile) child = g_file_enumerator_get_child (enumerator, info);
+      GFileType file_type = g_file_info_get_file_type (info);
 
-      if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+      if (!g_file_info_get_is_symlink (info) && file_type == G_FILE_TYPE_DIRECTORY)
         {
           if (!remove_directory_with_children (child, cancellable, error))
             return FALSE;
@@ -277,7 +279,9 @@ dzl_directory_reaper_execute_worker (GTask        *task,
             }
 
           enumerator = g_file_enumerate_children (p->glob.directory,
+                                                  G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK","
                                                   G_FILE_ATTRIBUTE_STANDARD_NAME","
+                                                  G_FILE_ATTRIBUTE_STANDARD_TYPE","
                                                   G_FILE_ATTRIBUTE_TIME_MODIFIED,
                                                   G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                                   cancellable,
@@ -292,9 +296,6 @@ dzl_directory_reaper_execute_worker (GTask        *task,
 
           while (NULL != (info = g_file_enumerator_next_file (enumerator, cancellable, NULL)))
             {
-              const gchar *name;
-
-              name = g_file_info_get_name (info);
               v64 = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
 
               /* mtime is in seconds */
@@ -302,21 +303,27 @@ dzl_directory_reaper_execute_worker (GTask        *task,
 
               if (v64 < now - p->min_age)
                 {
-                  g_autoptr(GFile) file = g_file_get_child (p->glob.directory, name);
+                  g_autoptr(GFile) file = g_file_enumerator_get_child (enumerator, info);
+                  GFileType file_type = g_file_info_get_file_type (info);
 
-                  if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable) == 
G_FILE_TYPE_DIRECTORY)
+                  if (g_file_info_get_is_symlink (info) || file_type != G_FILE_TYPE_DIRECTORY)
                     {
-                      if (!remove_directory_with_children (file, cancellable, &error) ||
-                          !g_file_delete (file, cancellable, &error))
+                      if (!g_file_delete (file, cancellable, &error))
                         {
                           g_warning ("%s", error->message);
                           g_clear_error (&error);
                         }
                     }
-                  else if (!g_file_delete (file, cancellable, &error))
+                  else
                     {
-                      g_warning ("%s", error->message);
-                      g_clear_error (&error);
+                      g_assert (file_type == G_FILE_TYPE_DIRECTORY);
+
+                      if (!remove_directory_with_children (file, cancellable, &error) ||
+                          !g_file_delete (file, cancellable, &error))
+                        {
+                          g_warning ("%s", error->message);
+                          g_clear_error (&error);
+                        }
                     }
                 }
 


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