diff options
author | Valentin Rothberg <valentinrothberg@gmail.com> | 2016-08-28 02:51:32 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-08-28 05:08:34 -0400 |
commit | 2f9cc12bb34a4a90f18839a5ce35e1e4d33d6413 (patch) | |
tree | 0f342e14c3cb1fe8f634a2a94cd6c18489ee6a6a /scripts/checkkconfigsymbols.py | |
parent | ef3f55438d95f0bfc5d4730db6e59058647832e2 (diff) |
checkkconfigsymbols: use arglist instead of cmd string
Splitting a command string could lead to unintended arguments. Use an
argument list in the execute() function instead.
Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'scripts/checkkconfigsymbols.py')
-rwxr-xr-x | scripts/checkkconfigsymbols.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py index 4b54aa342ac9..a32e4da4c117 100755 --- a/scripts/checkkconfigsymbols.py +++ b/scripts/checkkconfigsymbols.py | |||
@@ -149,11 +149,11 @@ def main(): | |||
149 | undefined_b = {} | 149 | undefined_b = {} |
150 | 150 | ||
151 | # get undefined items before the commit | 151 | # get undefined items before the commit |
152 | execute("git reset --hard %s" % commit_a) | 152 | reset(commit_a) |
153 | undefined_a, _ = check_symbols(args.ignore) | 153 | undefined_a, _ = check_symbols(args.ignore) |
154 | 154 | ||
155 | # get undefined items for the commit | 155 | # get undefined items for the commit |
156 | execute("git reset --hard %s" % commit_b) | 156 | reset(commit_b) |
157 | undefined_b, defined = check_symbols(args.ignore) | 157 | undefined_b, defined = check_symbols(args.ignore) |
158 | 158 | ||
159 | # report cases that are present for the commit but not before | 159 | # report cases that are present for the commit but not before |
@@ -170,7 +170,7 @@ def main(): | |||
170 | undefined[symbol] = files | 170 | undefined[symbol] = files |
171 | 171 | ||
172 | # reset to head | 172 | # reset to head |
173 | execute("git reset --hard %s" % head) | 173 | reset(head) |
174 | 174 | ||
175 | # default to check the entire tree | 175 | # default to check the entire tree |
176 | else: | 176 | else: |
@@ -202,6 +202,11 @@ def main(): | |||
202 | print() # new line | 202 | print() # new line |
203 | 203 | ||
204 | 204 | ||
205 | def reset(commit): | ||
206 | """Reset current git tree to %commit.""" | ||
207 | execute(["git", "reset", "--hard", commit]) | ||
208 | |||
209 | |||
205 | def yel(string): | 210 | def yel(string): |
206 | """ | 211 | """ |
207 | Color %string yellow. | 212 | Color %string yellow. |
@@ -219,25 +224,25 @@ def red(string): | |||
219 | def execute(cmd): | 224 | def execute(cmd): |
220 | """Execute %cmd and return stdout. Exit in case of error.""" | 225 | """Execute %cmd and return stdout. Exit in case of error.""" |
221 | try: | 226 | try: |
222 | cmdlist = cmd.split(" ") | 227 | stdout = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=False) |
223 | stdout = subprocess.check_output(cmdlist, stderr=subprocess.STDOUT, shell=False) | ||
224 | stdout = stdout.decode(errors='replace') | 228 | stdout = stdout.decode(errors='replace') |
225 | except subprocess.CalledProcessError as fail: | 229 | except subprocess.CalledProcessError as fail: |
226 | exit("Failed to execute %s\n%s" % (cmd, fail)) | 230 | exit(fail) |
227 | return stdout | 231 | return stdout |
228 | 232 | ||
229 | 233 | ||
230 | def find_commits(symbol, diff): | 234 | def find_commits(symbol, diff): |
231 | """Find commits changing %symbol in the given range of %diff.""" | 235 | """Find commits changing %symbol in the given range of %diff.""" |
232 | commits = execute("git log --pretty=oneline --abbrev-commit -G %s %s" | 236 | commits = execute(["git", "log", "--pretty=oneline", |
233 | % (symbol, diff)) | 237 | "--abbrev-commit", "-G", |
238 | symbol, diff]) | ||
234 | return [x for x in commits.split("\n") if x] | 239 | return [x for x in commits.split("\n") if x] |
235 | 240 | ||
236 | 241 | ||
237 | def tree_is_dirty(): | 242 | def tree_is_dirty(): |
238 | """Return true if the current working tree is dirty (i.e., if any file has | 243 | """Return true if the current working tree is dirty (i.e., if any file has |
239 | been added, deleted, modified, renamed or copied but not committed).""" | 244 | been added, deleted, modified, renamed or copied but not committed).""" |
240 | stdout = execute("git status --porcelain") | 245 | stdout = execute(["git", "status", "--porcelain"]) |
241 | for line in stdout: | 246 | for line in stdout: |
242 | if re.findall(r"[URMADC]{1}", line[:2]): | 247 | if re.findall(r"[URMADC]{1}", line[:2]): |
243 | return True | 248 | return True |
@@ -246,7 +251,7 @@ def tree_is_dirty(): | |||
246 | 251 | ||
247 | def get_head(): | 252 | def get_head(): |
248 | """Return commit hash of current HEAD.""" | 253 | """Return commit hash of current HEAD.""" |
249 | stdout = execute("git rev-parse HEAD") | 254 | stdout = execute(["git", "rev-parse", "HEAD"]) |
250 | return stdout.strip('\n') | 255 | return stdout.strip('\n') |
251 | 256 | ||
252 | 257 | ||
@@ -285,7 +290,7 @@ def find_sims(symbol, ignore, defined=[]): | |||
285 | def get_files(): | 290 | def get_files(): |
286 | """Return a list of all files in the current git directory.""" | 291 | """Return a list of all files in the current git directory.""" |
287 | # use 'git ls-files' to get the worklist | 292 | # use 'git ls-files' to get the worklist |
288 | stdout = execute("git ls-files") | 293 | stdout = execute(["git", "ls-files"]) |
289 | if len(stdout) > 0 and stdout[-1] == "\n": | 294 | if len(stdout) > 0 and stdout[-1] == "\n": |
290 | stdout = stdout[:-1] | 295 | stdout = stdout[:-1] |
291 | 296 | ||