Skip to content

Read Carriage Returns, Folded Lines, Eval, and Globs in a Directory Value in the Write Guard #2995

Closed

Description

@ptr727

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 $V form one word that $V can split into commit -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. classify folds every backslash-newline into a space before reading, while bash joins the two pieces into one word. So git -C "$W"\ followed by status\ and $V on the next lines reads as a quoted value, and bash builds -C from all three, letting $V split after it.
  • A value re-parsed by eval. In eval git -C "$W" status, the double quotes are removed before eval parses the command again, so the value splits there. A command that joins its arguments for a shell, such as watch, 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 literal git -C co* status is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pre-existingscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions