History

checkkconfigsymbols.py: avoid shell injection

Use subprocess and set shell to False to avoid potential shell injections.

Valentin Rothberg committed 10 years ago

Commit f175ba11 parent 4c73c081 file · +7 −5Browse files

Unified · Split

scripts/checkkconfigsymbols.py+7−5
@@ -2,7 +2,7 @@ · 1 unmodified line
22
33 """Find Kconfig symbols that are referenced but not defined."""
44
5−# (c) 2014-2015 Valentin Rothberg <valentinrothberg@gmail.com>
5+# (c) 2014-2016 Valentin Rothberg <valentinrothberg@gmail.com>
66 # (c) 2014 Stefan Hengelein <stefan.hengelein@fau.de>
77 #
88 # Licensed under the terms of the GNU GPL License version 2
@@ -12,6 +12,7 @@ import difflib · 3 unmodified lines
1212 import os
1313 import re
1414 import signal
15+import subprocess
1516 import sys
1617 from multiprocessing import Pool, cpu_count
1718 from optparse import OptionParser
@@ -222,10 +223,11 @@ def red(string): · 204 unmodified lines
222223
223224 def execute(cmd):
224225 """Execute %cmd and return stdout. Exit in case of error."""
225− pop = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True)
226− (stdout, _) = pop.communicate() # wait until finished
227− if pop.returncode != 0:
228− sys.exit(stdout)
226+ try:
227+ cmdlist = cmd.split(" ")
228+ stdout = subprocess.check_output(cmdlist, stderr=STDOUT, shell=False)
229+ except subprocess.CalledProcessError as fail:
230+ exit("Failed to execute %s\n%s" % (cmd, fail))
229231 return stdout
230232
231233