fix(shellexec): prevent empty XDG_* env vars when $SNAP is inherited from non-Wave snaps#3423
Closed
Jason-Shen2 wants to merge 1 commit into
Closed
fix(shellexec): prevent empty XDG_* env vars when $SNAP is inherited from non-Wave snaps#3423Jason-Shen2 wants to merge 1 commit into
Jason-Shen2 wants to merge 1 commit into
Conversation
…from non-Wave snaps Fixes wavetermdev#3336. Two compounding bugs: 1. Snap detection used os.Getenv("SNAP") != "", which triggers whenever wavesrv is launched from any snap process (not just Wave-as-snap). Changed to os.Getenv("SNAP_NAME") == "waveterm" for accurate detection. 2. UpdateCmdEnv would add empty-string values for env vars that didn't already exist in the command environment (e.g. KEY=). This caused tools like mise to write cache/config/data into relative CWD paths when the false-positive snap detection unset valid XDG vars. Added a check to skip adding new vars with empty values, matching the existing behavior for already-present vars.
Contributor
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe Snap environment correction in Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Author
|
Duplicate of #3402 which already fixes this issue. |
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
Fixes #3336.
When wavesrv was launched from a process that had $SNAP set (e.g., any CLI tool installed as a snap), the snap XDG-correction code would trigger erroneously. It then wrote empty-string values for
XDG_CONFIG_HOME,XDG_DATA_HOME,XDG_CACHE_HOME, etc. into the spawned shell environment, because PAM env typically doesn't set these variables on modern systems. Tools that path-join these vars without spec-compliant fallback (e.g. mise) then wrote their data into relative paths in the CWD.Changes
Two fixes:
Accurate snap detection (shellexec.go): Changed
os.Getenv("SNAP") != ""toos.Getenv("SNAP_NAME") == "waveterm". The $SNAP var propagates to child processes from any snap (e.g.taskCLI), causing false positives. $SNAP_NAME is set to the snap's own name and reliably identifies Wave-as-snap.Skip empty values for new env vars (shellutil.go):
UpdateCmdEnvalready correctly skipped empty values when updating existing env vars (unsetting them), but would add emptyKEY=entries for vars not already present. Added the sameenvVal != ""guard for the new-var branch, preventing empty-string variables from being injected into the child process environment.Testing
go build ./pkg/shellexec/... ./pkg/util/shellutil/...compiles cleanlygo test ./pkg/util/shellutil/...passes