1 |
Author: zmedico |
2 |
Date: 2009-08-28 09:04:42 +0000 (Fri, 28 Aug 2009) |
3 |
New Revision: 14167 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/portage/util.py |
7 |
Log: |
8 |
Bug #281834 - In getconfig(), do not allow definition of variables that have |
9 |
invalid names according to shell standards (such as names containing hyphens). |
10 |
|
11 |
|
12 |
Modified: main/trunk/pym/portage/util.py |
13 |
=================================================================== |
14 |
--- main/trunk/pym/portage/util.py 2009-08-27 09:08:45 UTC (rev 14166) |
15 |
+++ main/trunk/pym/portage/util.py 2009-08-28 09:04:42 UTC (rev 14167) |
16 |
@@ -16,6 +16,7 @@ |
17 |
import codecs |
18 |
import errno |
19 |
import logging |
20 |
+import re |
21 |
import shlex |
22 |
import stat |
23 |
import string |
24 |
@@ -379,6 +380,8 @@ |
25 |
(self.infile, str(e)), noiselevel=-1) |
26 |
return (newfile, StringIO()) |
27 |
|
28 |
+_invalid_var_name_re = re.compile(r'^\d|\W') |
29 |
+ |
30 |
def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): |
31 |
if isinstance(expand, dict): |
32 |
# Some existing variable definitions have been |
33 |
@@ -462,6 +465,16 @@ |
34 |
return mykeys |
35 |
key = _unicode_decode(key) |
36 |
val = _unicode_decode(val) |
37 |
+ |
38 |
+ if _invalid_var_name_re.search(key) is not None: |
39 |
+ if not tolerant: |
40 |
+ raise Exception(_( |
41 |
+ "ParseError: Invalid variable name '%s': line %s") % \ |
42 |
+ (key, lex.lineno - 1)) |
43 |
+ writemsg(_("!!! Invalid variable name '%s': line %s in %s\n") \ |
44 |
+ % (key, lex.lineno - 1, mycfg), noiselevel=-1) |
45 |
+ continue |
46 |
+ |
47 |
if expand: |
48 |
mykeys[key] = varexpand(val, expand_map) |
49 |
expand_map[key] = mykeys[key] |