-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add warning for /sdcard exec #2147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,60 @@ if [ -s /etc/acode_motd ]; then | |
| cat /etc/acode_motd | ||
| fi | ||
|
|
||
| check_binary_execution() { | ||
| local cmd="$1" | ||
| local cmd_path="" | ||
|
|
||
| # Ignore shell builtins, keywords, etc. | ||
| [[ -z "$cmd" ]] && return | ||
|
|
||
| # If user executed a path directly (./foo, /path/foo) | ||
| if [[ "$cmd" == */* ]]; then | ||
| cmd_path="$(realpath "$cmd" 2>/dev/null)" | ||
| else | ||
| cmd_path="$(command -v "$cmd" 2>/dev/null)" | ||
|
|
||
| # Resolve symlinks/relative paths | ||
| if [[ -n "$cmd_path" ]]; then | ||
| cmd_path="$(realpath "$cmd_path" 2>/dev/null)" | ||
| fi | ||
| fi | ||
|
|
||
| [[ -z "$cmd_path" ]] && return | ||
| [[ ! -f "$cmd_path" ]] && return | ||
|
|
||
| if [[ "$cmd_path" == /storage/* ]] || \ | ||
| [[ "$cmd_path" == /sdcard/* ]]; then | ||
| echo -e "\e[1;31m[!] ATTENTION REQUIRED\e[0m | ||
|
|
||
| \e[1;31mThe binary is located in:\e[0m | ||
| \e[36m$cmd_path\e[0m | ||
|
|
||
| \e[1;31mBinaries cannot be executed reliably from /sdcard or /storage.\e[0m | ||
| These locations are backed by Android's external storage layer and do not support normal Linux executable permissions. | ||
|
|
||
| Move your project or binary to a directory under: | ||
| \e[1;32m/home/\e[0m | ||
|
|
||
| Example: | ||
| \e[1;32mmv myproject ~/myproject\e[0m | ||
| \e[1;32mcd ~/myproject\e[0m | ||
|
|
||
| Then run the binary again. | ||
| " >&2 | ||
| fi | ||
| } | ||
|
|
||
| preexec() { | ||
| # Skip commands executed by the trap itself | ||
| [[ "$BASH_COMMAND" == trap* ]] && return | ||
|
|
||
| local cmd="${BASH_COMMAND%% *}" | ||
| check_binary_execution "$cmd" | ||
| } | ||
|
Comment on lines
+288
to
+293
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The comment says "Skip commands executed by the trap itself", but bash automatically suppresses DEBUG trap re-entrancy — the trap can't fire recursively inside its own handler. What this guard actually does is skip the warning when a user types a command that starts with Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| trap 'preexec' DEBUG | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+243
to
+295
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The |
||
|
|
||
| # Command-not-found handler | ||
| command_not_found_handle() { | ||
| cmd="$1" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preexecfunction name collides with bash-preexec conventionThe function name
preexecis the standard hook name used by the bash-preexec library, which Starship, fzf, and many other tools hook into. Using this exact name means any.bashrcthat sources bash-preexec will silently override this function (or vice versa), producing unpredictable results. Rename it to something app-specific to avoid the collision.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!