Skip to content

Commit 077b8e1

Browse files
author
vlkumiloslearning
committed
fix: replace subprocess which with shutil.which() in Process.exists()
The previous approach shelled out to the `which` binary via Popen, which has three problems: - `which` is not present on all systems (Alpine, minimal Docker images), causing an unhandled FileNotFoundError on every exists() call - any non-path text on stdout (e.g. zsh built-in printing "foo not found" to stdout) produced a false positive - spawning a subprocess for a PATH lookup is unnecessary overhead shutil is already imported and shutil.which() is already used by _resolve_tool() in the same class, as well as system_check.py and dependency.py. Using it here is consistent and correct on all platforms.
1 parent f62df1a commit 077b8e1

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

wifite/util/process.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ def exists(program):
200200
if Configuration.initialized and program in Configuration.existing_commands:
201201
return Configuration.existing_commands[program]
202202

203-
p2 = Process(['which', program])
204-
stdout = p2.stdout().strip()
205-
stderr = p2.stderr().strip()
206-
207-
exist = bool(stdout)
203+
exist = shutil.which(program) is not None
208204
if Configuration.initialized:
209205
Configuration.existing_commands.update({program: exist})
210206
return exist

0 commit comments

Comments
 (0)