matrix-rootfs: escaping filenames in os.system() commands
authorDaniel Bainton <daniel.bainton@movial.fi>
Thu, 12 Mar 2009 13:02:07 +0000 (15:02 +0200)
committerDaniel Bainton <daniel.bainton@movial.fi>
Thu, 12 Mar 2009 13:02:07 +0000 (15:02 +0200)
matrix/rootfs.py

index 82b157c..36a6b28 100644 (file)
@@ -126,6 +126,7 @@ class Builder(object):
        mkfs_ubifs = "mkfs.ubifs"
        ubinize = "ubinize"
        tar = "tar"
+       gzip = "gzip"
        flash_erase_size = 0x4000
        flash_pad_size = 0x3e00000
        # Compression to use
@@ -314,7 +315,7 @@ class Builder(object):
                                try:
                                        shutil.copy(f, path)
                                        if not f.endswith(".ko") and not self.no_strip:
-                                               os.system(self.strip + " " + os.path.join(path,os.path.basename(f)) + " &> /dev/null")
+                                               os.system(self.strip + " '" + os.path.join(path, os.path.basename(f)) + "' &> /dev/null")
                                except IOError, e:
                                        # We allow nonexistent files since only place where we'll get those
                                        # is from the include files directive
@@ -383,7 +384,7 @@ class Builder(object):
                                device_type,major,minor = self.devices[d]
                        else:
                                device_type,major,minor,mode = self.devices[d]
-                       os.system("%s -m %s %s %s %i %i" % (self.mknod, mode, os.path.join(basepath, 'dev', d), device_type, major, minor))
+                       os.system("%s -m %s '%s' %s %i %i" % (self.mknod, mode, os.path.join(basepath, 'dev', d), device_type, major, minor))
 
                # Fix permissions
                print "Adjusting ownerships and permissions..."
@@ -415,17 +416,17 @@ class Builder(object):
                                dir = dir[1:]
                        if os.path.exists(os.path.join(basepath, dir)):
                                user,group = self.change_owner[d]
-                               os.system("%s %s.%s -R %s/%s " % (self.chown, user, group, basepath, dir))
+                               os.system("%s %s.%s -R '%s/%s' " % (self.chown, user, group, basepath, dir))
 
                # Build rootfs
                if build_target == "all" or build_target == "rootfs":
                        print "Creating a rootfs..."
-                       os.system("%s -c --one-file-system -C %s -z -f %s.tar.gz ." % (self.tar, basepath, basepath))
+                       os.system("%s -c --one-file-system -C '%s' -z -f '%s.tar.gz' ." % (self.tar, basepath, basepath))
 
                # Build jffs2
                if build_target == "all" or build_target == "jffs2":
                        print "Creating a root image as JFFS2..."
-                       os.system("%s -p%d -n -e%d -r %s -o %s.jffs2" % (self.mkfs_jffs2, self.flash_pad_size, self.flash_erase_size, basepath, basepath))
+                       os.system("%s -p%d -n -e%d -r '%s' -o '%s.jffs2'" % (self.mkfs_jffs2, self.flash_pad_size, self.flash_erase_size, basepath, basepath))
 
                # Build ubifs
                if build_target == "ubi":
@@ -444,16 +445,16 @@ class Builder(object):
                        f.write(ubinize_config)
                        f.close()
 
-                       os.system("%s --compr=%s -r %s -o %s.ubifs -m %d -e %d -c %d" % (self.mkfs_ubifs, self.flash_compression, basepath, basepath, self.ubifs_min_io_size, self.ubifs_leb_size, self.ubifs_max_leb_count))
-                       os.system("%s -m %d -p %d -o %s.ubi %s/ubinize.cfg" % (self.ubinize, self.ubifs_min_io_size, self.ubinize_peb_size, basepath, self.builddir))
+                       os.system("%s --compr=%s -r '%s' -o '%s.ubifs' -m %d -e %d -c %d" % (self.mkfs_ubifs, self.flash_compression, basepath, basepath, self.ubifs_min_io_size, self.ubifs_leb_size, self.ubifs_max_leb_count))
+                       os.system("%s -m %d -p %d -o '%s.ubi' '%s/ubinize.cfg'" % (self.ubinize, self.ubifs_min_io_size, self.ubinize_peb_size, basepath, self.builddir))
 
                # Build development rootfs
                if build_target == "all" or build_target == "devrootfs":
                        print "Creating a rootstrap..."
-                       os.system("%s -c --one-file-system -C %s -f %s-rootstrap.tar ." % ("tar", self.path, basepath))
+                       os.system("%s -c --one-file-system -C '%s' -f '%s-rootstrap.tar' ." % (self.tar, self.path, basepath))
                        # override passwd/group with the modified versions
-                       os.system("%s -r -C %s -f %s-rootstrap.tar ./etc/passwd ./etc/group" % ("tar", basepath, basepath))
-                       os.system("%s -f %s-rootstrap.tar" % ("gzip", basepath))
+                       os.system("%s -r -C '%s' -f '%s-rootstrap.tar' ./etc/passwd ./etc/group" % (self.tar, basepath, basepath))
+                       os.system("%s -f '%s-rootstrap.tar'" % (self.gzip, basepath))
 
                os.chdir(old_dir)
 
@@ -471,4 +472,4 @@ class Builder(object):
                if clean:
                        print "Cleaning up"
                        os.remove("/tmp/env.faked")
-                       os.system("rm -rf %s" % basepath)
+                       os.system("rm -rf '%s'" % basepath)