From 03745206b8e26bb7a3e7119abcd8a03d95dbc897 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sat, 16 Jun 2012 10:57:52 -0700 Subject: Add a restricted set of characters which can be used in filenames when cleaning them. --- cloudinit/util.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'cloudinit/util.py') diff --git a/cloudinit/util.py b/cloudinit/util.py index ed12dada..6e8ce96e 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -64,6 +64,7 @@ LOG = logging.getLogger(__name__) FN_REPLACEMENTS = { os.sep: '_', } +FN_ALLOWED = ('_-.()' + string.digits + string.ascii_letters) # Helper utils to see if running in a container CONTAINER_TESTS = ['running-in-container', 'lxc-is-container'] @@ -227,7 +228,14 @@ def read_conf(fname): def clean_filename(fn): for (k, v) in FN_REPLACEMENTS.iteritems(): fn = fn.replace(k, v) - return fn.strip() + removals = [] + for k in fn: + if k not in FN_ALLOWED: + removals.append(k) + for k in removals: + fn = fn.replace(k, '') + fn = fn.strip() + return fn def decomp_str(data): -- cgit v1.2.3