Fix: address code review findings across core, tui, and tab scripts#1296
Open
Abs313a wants to merge 3 commits into
Open
Fix: address code review findings across core, tui, and tab scripts#1296Abs313a wants to merge 3 commits into
Abs313a wants to merge 3 commits into
Conversation
| apt-get|nala) | ||
| curl -Lo discord.deb "https://discord.com/api/download?platform=linux&format=deb" | ||
| # Ensure the downloaded .deb is removed even on failure under `set -e`. | ||
| trap 'rm -f discord.deb' EXIT |
Contributor
Author
There was a problem hiding this comment.
@ChrisTitusTech This was meant to clean up discord.deb if curl or the package install fails under set -e; otherwise the later rm is skipped.
That said, I agree it is more machinery than this script needs and trap - EXIT can wipe a previous EXIT trap if one is ever added. I can simplify it to match the surrounding install scripts..
# Conflicts: # core/tabs/common-script.sh
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.
Type of Change
Description
This PR bundles independent fixes found during code review. Each change addresses a specific, reproducible bug. Grouped by category:
Security
core/tabs/utils/ssh.shThe "Add a new system" flow appended
StrictHostKeyChecking noandUserKnownHostsFile=/dev/nullto~/.ssh/configfor every host, silently disabling MITM protection. Both lines removed; SSH now uses default secure-by-default behavior.core/tabs/common-script.sh:checkEscalationToolWhen running as root,
ESCALATION_TOOLwas set toeval, so every"$ESCALATION_TOOL" cmd "$arg"invocation across all 170 tab scripts re-tokenized and re-expanded its arguments. Paths containing spaces split into multiple args; shell metacharacters were re-interpreted, opening an injection vector. Replaced withenv, which runs the command in the current environment without re-parsing.Logic
core/src/inner.rs:Entry::is_supportedThe
SystemDataType::FileExistsprecondition arm ignored thematchesflag, so[[preconditions]] matches = false, data = "file_exists", values = …behaved identically tomatches = true. Three sibling arms (Environment,ContainingFile,CommandExists) all compare== *matches; this arm now does the same.core/tabs/common-script.sh:checkSuperUserPrivileged-group detection used unanchored
grep, so groups likewheelchair,rooted, orsudoerswere accepted aswheel/root/sudo. Switched to whole-word match againstid -nGvia POSIXcase. Additionally, the final guardgrep -q "${SUGROUP}"ran withSUGROUPunset when no super-user group was found. Becausegrep -q ""matches every line, unprivileged users silently passed. Added explicit[ -z "$SUGROUP" ]fail-fast.core/tabs/common-service-script.sh:startAndEnableServiceThe
sv(runit) branch only calledenableServiceand neverstartService, contradicting the function name. The systemd branch (enable --now) and openrc branch (explicitstartService) both start the service; sv now matches.Stability - eliminating TUI panics
tui/src/floating_text.rs:from_command.unwrap()on anOptionthat wasNoneforCommand::Noneand forLocalFileread errors crashed the TUI when previewing an unreadable file. Now renders a fallback string.tui/src/running_command.rs:kill_childUnconditional
.take().unwrap()panicked on double-call (rapid Ctrl-C while the child was being killed but had not yet exited), andrecv().unwrap()panicked when the spawn thread dropped its sender after aspawn_commandfailure. Both failure modes are now no-ops.tui/src/running_command.rs:screenpty_master.resize(...).unwrap()ran every frame and panicked mid-draw on a closed pty (child exited) or zero-dimension target (extreme terminal resize). Failures now ignored; the screen still renders from the existing buffer.tui/src/confirmation.rs:scroll_downself.names.len() - 1underflowedusizeand panicked if aConfirmPromptwas ever constructed with an empty list. Replaced withsaturating_sub(1).core/src/inner.rs:get_shebangreader.lines().next().unwrap().unwrap()panicked at startup on any script whose only bytes were#!(no newline) or whose shebang line contained invalid UTF-8, aborting the entire TUI before any UI was drawn. Now falls back to the default executable.Hardening - installer scripts
core/tabs/common-script.sh(AUR yay-bin install path)cd /opt && git clone …failed when/opt/yay-binalready existed;chown -R "$USER":"$USER"failed when$USERwas unset (cron,su -c); relativecd yay-binwas fragile. Pre-clean/opt/yay-bin, fall back toid -unfor the install user, use absolutecd /opt/yay-bin.core/tabs/applications-setup/communication-apps/discord-setup.shUnder
#!/bin/sh -e, anapt-get install ./discord.debfailure aborted the script before the cleanuprm, leaving the deb in CWD. Addedtrap 'rm -f discord.deb' EXIT. Also switchedcurl -Lotocurl -fLoso HTTP errors fail loudly instead of writing an HTML error body as the .deb.core/tabs/applications-setup/linutil-installer.sh:install_extracurl 'https://raw.githubusercontent.com/…' | tee /usr/share/…lacked-f, so a 404/5xx from GitHub would write the HTML error body into/usr/share/man/man1/linutil.1and/usr/share/applications/linutil.desktopas root. Switched both fetches tocurl -fsSL.Verification
All checks pass on the modified tree:
cargo check --workspace --all-targetscargo clippy --workspace --all-targets -- -D warningscargo fmt --checkshellcheckon all modified shell scriptsNotable behavior change
common-script.sh:checkEscalationToolnow setsESCALATION_TOOL="env"instead of"eval"when running as root. For all in-repo callers this is a drop-in replacement; the difference is that env passes args through untouched while eval re-parsed them as shell input (the injection vector this fixes). Callers that intentionally relied on eval's re-parsing, for example passing"apt-get install -y firefox"as a single quoted string, will need to switch to already-tokenized args.