]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson-render-jinja2: use ast.literal_eval()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 5 Nov 2021 10:51:17 +0000 (11:51 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 5 Nov 2021 13:56:32 +0000 (14:56 +0100)
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.

tools/meson-render-jinja2.py

index b811a1549303994302bdf2e275543fac50797423..9a6fc7c31c88eccf02484138d2ab7d2e04b3c0e5 100755 (executable)
@@ -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