appliance: Don't set utime on cachedir until we know it is safe.
authorRichard W.M. Jones <rjones@redhat.com>
Sat, 11 Dec 2010 23:35:18 +0000 (23:35 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sat, 11 Dec 2010 23:35:50 +0000 (23:35 +0000)
This could be used to touch an arbitrary file (albeit one which
must already exist), and this could have been a security problem.

src/appliance.c

index 30eb6fd..1b6b505 100644 (file)
@@ -320,7 +320,6 @@ check_for_cached_appliance (guestfs_h *g,
   snprintf (filename, len, "%s/checksum", cachedir);
 
   (void) mkdir (cachedir, 0755);
   snprintf (filename, len, "%s/checksum", cachedir);
 
   (void) mkdir (cachedir, 0755);
-  (void) utime (cachedir, NULL);
 
   /* See if the cache directory exists and passes some simple checks
    * to make sure it has not been tampered with.
 
   /* See if the cache directory exists and passes some simple checks
    * to make sure it has not been tampered with.
@@ -344,6 +343,8 @@ check_for_cached_appliance (guestfs_h *g,
     return -1;
   }
 
     return -1;
   }
 
+  (void) utime (cachedir, NULL);
+
   garbage_collect_appliances (cachedir);
 
   /* Try to open and acquire a lock on the checksum file. */
   garbage_collect_appliances (cachedir);
 
   /* Try to open and acquire a lock on the checksum file. */