summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-28 09:04:42 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-28 09:04:42 +0000
commit68a803b2cfcdea5b649873a7680f5ba719462698 (patch)
tree60f9fd211e07b14af817c9d243e94f7ba7d4ca69 /pym
parent35d9537a14714a80c40eaeaed2a6f17b05897103 (diff)
downloadportage-68a803b2cfcdea5b649873a7680f5ba719462698.tar.gz
portage-68a803b2cfcdea5b649873a7680f5ba719462698.tar.bz2
portage-68a803b2cfcdea5b649873a7680f5ba719462698.zip
Bug #281834 - In getconfig(), do not allow definition of variables that have
invalid names according to shell standards (such as names containing hyphens). svn path=/main/trunk/; revision=14167
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/util.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/pym/portage/util.py b/pym/portage/util.py
index 6f11934e8..9f7c92828 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -16,6 +16,7 @@ import commands
import codecs
import errno
import logging
+import re
import shlex
import stat
import string
@@ -379,6 +380,8 @@ class _tolerant_shlex(shlex.shlex):
(self.infile, str(e)), noiselevel=-1)
return (newfile, StringIO())
+_invalid_var_name_re = re.compile(r'^\d|\W')
+
def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
if isinstance(expand, dict):
# Some existing variable definitions have been
@@ -462,6 +465,16 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
return mykeys
key = _unicode_decode(key)
val = _unicode_decode(val)
+
+ if _invalid_var_name_re.search(key) is not None:
+ if not tolerant:
+ raise Exception(_(
+ "ParseError: Invalid variable name '%s': line %s") % \
+ (key, lex.lineno - 1))
+ writemsg(_("!!! Invalid variable name '%s': line %s in %s\n") \
+ % (key, lex.lineno - 1, mycfg), noiselevel=-1)
+ continue
+
if expand:
mykeys[key] = varexpand(val, expand_map)
expand_map[key] = mykeys[key]