Package: schroot
Version: 1.4.7
Severity: important

schroot allows me to create a persistent session with a particular name, such 
as "zcarter-catalan-build-cb67j4yZoS-16646".   

However, when I attempt to access it later on, it fails like this:

$  /usr/bin/schroot -p -v -r -c zcarter-catalan-build-cb67j4yZoS-16646 -- uname 
-a
E: zcarter-catalan-build-cb67j4yZoS-16646: Chroot not found

I traced it down to the is_valid_filename() function defined in sbuild-util.cc

When schroot scans all the files in the session directory, it is skipping those 
that don't match certain regex restrictions, even though they are valid 
filenames, and were created by the same version of 
schroot.

This is a regression from behaviour not present in the 1.2 series.

I see two solutions, either:
- enforce the same restrictions when the chroot session is first created.
- loosen the restrictions, since the run-parts() restrictions do not seem 
appropriate to restrict session names.

My vote would be for the latter solution.  

I'm attaching a patch that works for me.

thanks!

-Zach

--- ./sbuild/sbuild-util.cc.orig	2010-07-21 15:11:30.000000000 -0700
+++ ./sbuild/sbuild-util.cc	2010-07-21 15:18:12.000000000 -0700
@@ -170,6 +170,20 @@
 }
 
 bool
+sbuild::is_valid_sessionname (std::string const& name)
+{
+  bool match = false;
+
+  static regex file_namespace("^[a-zA-Z0-9][a-zA-Z0-9_-]*$");
+
+  if (regex_search(name, file_namespace)) {
+    match = true;
+  }
+
+  return match;
+}
+
+bool
 sbuild::is_valid_filename (std::string const& name,
 			   bool               lsb_mode)
 {
--- ./sbuild/sbuild-util.h.orig	2010-07-21 15:20:33.000000000 -0700
+++ ./sbuild/sbuild-util.h	2010-07-21 15:17:38.000000000 -0700
@@ -79,6 +79,17 @@
   /**
    * Check if a filename matches the allowed pattern(s).  This will
    * not match dotfiles, backup files, dpkg configuration backup
+   * files, etc. 
+   *
+   * @param name the filename to check.
+   * @returns true if it matches, false if not.
+   */
+  bool
+  is_valid_sessionname (std::string const& name);
+
+  /**
+   * Check if a filename matches the allowed pattern(s).  This will
+   * not match dotfiles, backup files, dpkg configuration backup
    * files, etc.  This uses the same rules as run-parts(8).
    *
    * @param name the filename to check.
--- ./sbuild/sbuild-chroot-config.cc.orig	2010-07-21 15:19:21.000000000 -0700
+++ ./sbuild/sbuild-chroot-config.cc	2010-07-21 15:19:34.000000000 -0700
@@ -139,7 +139,7 @@
 	continue;
 
       // Skip backup files and dpkg configuration backup files.
-      if (!is_valid_filename(name))
+      if (!is_valid_sessionname(name))
 	continue;
 
       std::string filename = dir + "/" + name;

Reply via email to