fix: replace subprocess which with shutil.which() in Process.exists()#524
Merged
kimocoder merged 2 commits intoJun 3, 2026
Merged
Conversation
…or precedence bug `not stdout == stderr == ''` is evaluated as `not (stdout == stderr == '')` which returns True when stderr is non-empty (e.g. "service not found"), causing wifite to believe the tool exists and then crash with FileNotFoundError. Replace with `bool(stdout)` — which is non-empty only when `which` actually found the binary. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Owner
|
/claude |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Process.exists()inwifite/util/process.pyshelled out to thewhichbinary viaPopento check if a tool is installed. This had three problems:1. Operator precedence bug (original crash)
Evaluated as
not (stdout == stderr == ''). Whenwhich servicefails, stdout is''but stderr is'service not found'— so the chain returnsFalse,not False→True, and wifite crashes trying to exec a missing binary.2. Fragile on minimal systems
whichis not present on Alpine, minimal Docker images, or some chroots.Popen(['which', ...])raises an unhandledFileNotFoundError, crashing everyexists()call site.3. Inconsistent with the rest of the codebase
shutilis already imported in this file._resolve_tool()in the same class usesshutil.which(). So doessystem_check.pyanddependency.py. The subprocess approach was the only outlier.Fix
Replace the entire subprocess block with a single in-process call:
This is correct, portable, and consistent with every other tool-detection pattern in the codebase.
Test plan
wifite --killon a system whereserviceis not installed (e.g. Arch Linux) — should no longer crashaircrack-ng,tshark, etc.)Falsecorrectly