bug: prevent tmux history paths from corrupting shell commands - #94
Merged
Conversation
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.
Bug
.local/bin/tmux-historyembedded its temporary capture-file path directly inside a single-quoted shell command. A validTMPDIRcontaining an apostrophe broke the generated command, so Neovim received a corrupted path and the real terminal-history file was left on disk.Severity and impact
This is a correctness and reliability bug with a cleanup/privacy consequence. Apostrophes are valid in Unix paths. In that environment the command opens the wrong file while terminal history remains in the temporary directory.
Evidence
Relevant code:
.local/bin/tmux-history.The parent implementation interpolated the path into a shell string shaped like:
That is not valid escaping when
$fileitself contains'. Becausetmux new-windowevaluates the supplied command through a shell, the apostrophe terminates the word and changes argument boundaries.Observed with a temporary directory named
tmp'quote:The actual capture under
tmp'quotewas left behind.Reproduce
Use temporary, uncommitted
tmuxandnvimstubs:tmux display-messageprints0.tmux capture-paneprints sample history.tmux new-windowexecutes its command argument withbash -c.nvimrecords its final argument.Then run:
Actual result before the fix: the recorded Neovim path loses the literal apostrophe and absorbs command text; the genuine capture file remains.
Expected result: Neovim receives the exact
mktemppath, including the apostrophe, and that capture file is removed afterward.Root cause
The implementation treated surrounding values with literal single quotes as general shell escaping. A value containing a single quote invalidates that quoting when the complete command is reparsed by the shell.
Fix
Build the window command with Bash
printf %qfor every dynamic argument:This retains the existing tmux-shell execution model while preserving each value as one literal shell argument.
Validation
The temporary harness was run before the committed test artifact was removed:
bash -n .local/bin/tmux-historypassed.GitHub comparison against
masternow shows only.local/bin/tmux-historychanged (3 additions, 1 deletion). No test or reproduction artifact is included in the PR.Scope
Pane capture, history trimming, Neovim position/mapping, window naming, temporary-file naming, dependencies, and unrelated scripts are intentionally unchanged. No tests, fixtures, snapshots, repro scripts, logs, or evidence-only files are added or modified.