mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 06:31:31 +00:00
moveconfig: replace unsafe eval with asteval
Commit b237d358b4
("moveconfig: expand simple expressions") added
support for expanding expressions in configs, but used the unsafe python
built-in "eval". This patch fixes this by replacing eval with the
asteval module.
Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Heiko Schocher <hs@denx.de>
Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
parent
080cc0b1b3
commit
b3192f48c1
1 changed files with 3 additions and 1 deletions
|
@ -295,6 +295,7 @@ To see the complete list of supported options, run
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import asteval
|
||||||
import collections
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import difflib
|
import difflib
|
||||||
|
@ -808,10 +809,11 @@ def try_expand(line):
|
||||||
return line
|
return line
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
aeval = asteval.Interpreter( usersyms=SIZES, minimal=True )
|
||||||
cfg, val = re.split("=", line)
|
cfg, val = re.split("=", line)
|
||||||
val= val.strip('\"')
|
val= val.strip('\"')
|
||||||
if re.search("[*+-/]|<<|SZ_+|\(([^\)]+)\)", val):
|
if re.search("[*+-/]|<<|SZ_+|\(([^\)]+)\)", val):
|
||||||
newval = hex(eval(val, SIZES))
|
newval = hex(aeval(val))
|
||||||
print("\tExpanded expression %s to %s" % (val, newval))
|
print("\tExpanded expression %s to %s" % (val, newval))
|
||||||
return cfg+'='+newval
|
return cfg+'='+newval
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Add table
Reference in a new issue