Repository navigation
[P0] fix(#555): mkdir/touch/cp/rm/rmdir re-expand already-expanded argv - silent wrong-path corruption - #558
Merged
Conversation
…gv - silent wrong-path corruption Five sibling wrappers in external_file_builtins.rs ran their operands through expand_word AFTER the simple-command executor had already expanded the argv once. GNU bash-5.3 expands simple-command words exactly once, at dispatch: execute_cmd.c:4617 (execute_simple_command) runs the single expand_words pass, execute_cmd.c:4938 hands the expanded words to execute_disk_command, and those words become the final execve argv (execute_cmd.c:6126 shell_execve -> :6133 execve) - nothing downstream re-scans operand text. Redirections follow the same once-only timing (redir.c:789/:909 redirection_expand, then redir.c:701 redir_open opens the result verbatim). mkdir/touch/cp/rm/ rmdir are coreutils utilities in GNU: the shell contracts with them on final argv, and the utility's diagnostics quote the operand verbatim (verified behaviorally on WSL 5.3.0, script-file probes, 2026-10-12). A single-quoted or escaped operand like '$FIX/d' therefore arrives at those wrapper loops with its quotes removed and a live-looking dollar; the second expand_word pass re-scanned that literal text and silently created, touched, copied into, or REMOVED the wrong path: 'mkdir $FIX/d' built zz/d, and 'rm $FIX/r' deleted an existing zz/r with exit 0. Same P0 silent-corruption class as #511 (fixed by #552 for cat) and #177 (sed, same file). Use the argv as-is in every operand loop (mkdir, touch, cp, rm, rmdir) and in cp's -t/--target-directory value consumption; pathname/glob expansion already happened once at dispatch. rubash's own wrapper leniencies (mkdir's create_dir_all implies -p, rmdir swallowing per-operand errors) are pre-existing contracts this change does not alter. Tests: tests/issue555_file_builtin_family_regressions (22 cases; the family table + shared assert_literal_operand_contract helper covers one row per wrapper so the next wrapper added to this file cannot quietly reintroduce the second expansion; live-expansion controls included; 19/22 fail on unfixed master, 22/22 pass with this change).
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
Closes #555. Same P0 silent-corruption class as #511 (fixed by #552): the five sibling wrappers in
src/executor/external_file_builtins.rs—external_mkdir,external_touch,external_cp,external_rm,external_rmdir— re-ranexpand_wordover argv the simple-command executor had already expanded once. A single-quoted/escaped operand like$FIX/darrives with its quotes removed and a live-looking dollar, so the second pass re-scanned the literal text and silently created/touched/copied-into/REMOVED the wrong path. Worst member:rm '$FIX/r'deleted an existingzz/rwith exit 0.Fix (argv as-is, the #552/#177 rule)
cmd.wordsentries as-is; the secondexpand_wordpass is dropped.external_cp's-t/--target-directoryVALUE consumption took the operand too — fixed the same way.GNU anchors (vendored bash-5.3-16-gb4608166, behavior-level)
Tests
tests/issue555_file_builtin_family_regressions.rs— 22 cases mirroring the issue511 suite:Casetable +assert_literal_operand_contract): guard-path polarity, literal-path application, literal text in diagnostics, exit status — one row per wrapper so the next wrapper added to this file cannot quietly reintroduce the second expansion;$VAR, escaped$VAR, unset-variable literal, plus rm/touch failing-operand loop continuation;$VARfor all five), command-substitution dispatch, pathname-at-dispatch control.Evidence (real rubash.exe, probes + cargo):
cargo test --no-fail-faston both (172 targets each): failure sets bidirectionally identical by name except the 19 issue555 names — 67 pre-existing failures shared byte-for-byte (including the redir golden reds owned by other waves), zero fix-only failures.Notes / follow-up
external_mkfifoin the same file still has a secondexpand_word, but its operand only feeds an error message (mkfifo always fails on Windows) — no filesystem action, no corruption path. Left out of this issue's scope; worth a row in this table if it ever gains a create path.