aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-02-21 02:48:32 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2015-02-21 02:48:32 +0200
commitc7e3d84f51158aad337e72b70f72f5460c2cb640 (patch)
treec07092b2bbc72113f2a2109736b33f4fc9805fda
parent75a0bc835051daa5ca6a202cff57e40912d7979d (diff)
downloadmeson-c7e3d84f51158aad337e72b70f72f5460c2cb640.zip
meson-c7e3d84f51158aad337e72b70f72f5460c2cb640.tar.gz
meson-c7e3d84f51158aad337e72b70f72f5460c2cb640.tar.bz2
Validate variable names better in assignment.
-rw-r--r--interpreter.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/interpreter.py b/interpreter.py
index c1e4547..65e1b4e 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -21,7 +21,7 @@ import build
import optinterpreter
import wrap
import mesonlib
-import os, sys, platform, subprocess, shutil, uuid
+import os, sys, platform, subprocess, shutil, uuid, re
class InterpreterException(coredata.MesonException):
pass
@@ -786,16 +786,18 @@ class Interpreter():
if len(args) != 2:
raise InvalidCode('Set_variable takes two arguments.')
varname = args[0]
- if not isinstance(varname, str):
- raise InvalidCode('First argument to set_variable must be a string.')
value = self.to_native(args[1])
self.set_variable(varname, value)
def set_variable(self, varname, variable):
if variable is None:
raise InvalidCode('Can not assign None to variable.')
+ if not isinstance(varname, str):
+ raise InvalidCode('First argument to set_variable must be a string.')
if not self.is_assignable(variable):
raise InvalidCode('Assigned value not of assignable type.')
+ if re.fullmatch('[_a-zA-Z][_0-9a-zA-Z]*', varname) is None:
+ raise InvalidCode('Invalid variable name: ' + varname)
if varname in self.builtin:
raise InvalidCode('Tried to overwrite internal variable "%s"' % varname)
self.variables[varname] = variable