summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-05 11:51:17 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-05 14:56:32 +0100
commit5f035b13deb15daab34c2b5da30fabe8600fd803 (patch)
tree6c2daec1d7882c9e9658c99ec6204ca9c632fd01 /tools
parent7f9521d5e12ca9b1bee530dfe2e0218c07f3d7fa (diff)
downloadsystemd-5f035b13deb15daab34c2b5da30fabe8600fd803.tar.gz
meson-render-jinja2: use ast.literal_eval()
Imports are sorted in the usual fashion: stdlib first. literal_eval() parses string/numbers/lists/sets/dicts, and nothing else, while eval will execute any python code. Using literal_eval() is generally more correct, because it avoids the risk of side effects from the parsed expression. In this case, we generate the parsed strings ourselves, so it's very unlikely to have anything unexpected in the expressions. But let's do the correct thing anyway.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/meson-render-jinja2.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/meson-render-jinja2.py b/tools/meson-render-jinja2.py
index b811a15493..9a6fc7c31c 100755
--- a/tools/meson-render-jinja2.py
+++ b/tools/meson-render-jinja2.py
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
-import jinja2
+import ast
import re
import sys
+import jinja2
+
def parse_config_h(filename):
# Parse config.h file generated by meson.
ans = {}
@@ -14,7 +16,7 @@ def parse_config_h(filename):
continue
a, b = m.groups()
if b and b[0] in '0123456789"':
- b = eval(b)
+ b = ast.literal_eval(b)
ans[a] = b
return ans