Use subprocess and set shell to False to avoid potential shell injections.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -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 2 | 8 | # Licensed under the terms of the GNU GPL License version 2 |
| @@ -12,6 +12,7 @@ import difflib · 3 unmodified lines | |||
| 12 | import os | 12 | import os |
| 13 | import re | 13 | import re |
| 14 | import signal | 14 | import signal |
| 15 | import subprocess | ||
| 15 | import sys | 16 | import sys |
| 16 | from multiprocessing import Pool, cpu_count | 17 | from multiprocessing import Pool, cpu_count |
| 17 | from optparse import OptionParser | 18 | from optparse import OptionParser |
| @@ -222,10 +223,11 @@ def red(string): · 204 unmodified lines | |||
| 222 | 223 | ||
| 223 | def execute(cmd): | 224 | def 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 finished | 227 | 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 stdout | 231 | return stdout |
| 230 | 232 | ||
| 231 | 233 | ||