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

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/checkkconfigsymbols.py+7−5
@@ -2,7 +2,7 @@ · 1 unmodified line
2 2
3"""Find Kconfig symbols that are referenced but not defined."""3"""Find Kconfig symbols that are referenced but not defined."""
4 4
5# (c) 2014-2015 Valentin Rothberg <valentinrothberg@gmail.com>5# (c) 2014-2016 Valentin Rothberg <valentinrothberg@gmail.com>
6# (c) 2014 Stefan Hengelein <stefan.hengelein@fau.de>6# (c) 2014 Stefan Hengelein <stefan.hengelein@fau.de>
7#7#
8# Licensed under the terms of the GNU GPL License version 28# Licensed under the terms of the GNU GPL License version 2
@@ -12,6 +12,7 @@ import difflib · 3 unmodified lines
12import os12import os
13import re13import re
14import signal14import signal
15import subprocess
15import sys16import sys
16from multiprocessing import Pool, cpu_count17from multiprocessing import Pool, cpu_count
17from optparse import OptionParser18from optparse import OptionParser
@@ -222,10 +223,11 @@ def red(string): · 204 unmodified lines
222 223
223def execute(cmd):224def execute(cmd):
224 """Execute %cmd and return stdout. Exit in case of error."""225 """Execute %cmd and return stdout. Exit in case of error."""
225 pop = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True)226 try:
226 (stdout, _) = pop.communicate() # wait until finished227 cmdlist = cmd.split(" ")
227 if pop.returncode != 0:228 stdout = subprocess.check_output(cmdlist, stderr=STDOUT, shell=False)
228 sys.exit(stdout)229 except subprocess.CalledProcessError as fail:
230 exit("Failed to execute %s\n%s" % (cmd, fail))
229 return stdout231 return stdout
230 232
231 233