From 68a803b2cfcdea5b649873a7680f5ba719462698 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 28 Aug 2009 09:04:42 +0000 Subject: 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 --- pym/portage/util.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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] -- cgit v1.2.3-1-g7c22