Repository navigation
Description
Context
Found by the local review of the fix for #2977, which denies a -C, --git-dir, or --work-tree value that word splitting may split. Each shape is allowed by develop's guard too, since develop exempts every directory value. Each was confirmed in bash with git replaced by a function printing its arguments, and found by a classify probe on constructed commands.
Directory Values the Split-Free Test Still Reads as One Word
- A carriage return between words. In
git -C "$W"<CR>status<CR>$V, bash reads no word break at a carriage return, so the quoted value,status, and the unquoted$Vform one word that$Vcan split intocommit -n -m y. The guard's lexers read a carriage return as whitespace, so"$W"reads as a quoted value of its own. - A backslash-newline inside the command.
classifyfolds every backslash-newline into a space before reading, while bash joins the two pieces into one word. Sogit -C "$W"\followed bystatus\and$Von the next lines reads as a quoted value, and bash builds-Cfrom all three, letting$Vsplit after it. - A value re-parsed by
eval. Ineval git -C "$W" status, the double quotes are removed beforeevalparses the command again, so the value splits there. A command that joins its arguments for a shell, such aswatch, does the same. - Pathname expansion in the value. In
git -C "$P"* status, the glob can expand to several directory names, so a directory named like a subcommand becomes the subcommand. A literalgit -C co* statusis not checked at all, since it holds no run-time word.
Two neighbouring shapes, outside the directory rule, hide a whole git command from the tokens. A doubled backslash before a newline, as in echo \\ followed by a line running git commit --no-verify -m x, is folded as a line continuation that bash does not make. An escaped carriage return before a newline is folded the same way.
Possible Direction
Fail closed as the rest of this class does. Treat a carriage return inside a command as unreadable, fold only a backslash-newline whose backslash is itself unescaped, read the arguments of eval and watch the way a wrapper body is read with its quotes already removed, and count an unquoted glob character in a directory value as a word that may split.
Activity
Fail Closed on Split Directory Values and Hidden Git Command Words in…
Read Every Launcher and Exported Git Directory in the Write Guard (#3342
Read Tokenizer, Directory-Value, and Launched-String Gaps in the Writ…