Skip to content

POSIX-path fallback rewrites message/annotation args: commit/tag -m '/c' is stored as 'c:/' #5

Closed

Description

@caomengxuan666

Summary

patches/0002-mingw-accept-posix-shaped-path-arguments.patch (the
"accept POSIX-shaped path arguments" feature) applies its rewrite to every
argv element from argv[1] on — with no notion of which position the
argument occupies. git commit -m, git tag -m, git notes -m message
payloads are not path arguments, but if the message is a single token shaped
like /x... and the converted Windows path exists on the machine, it gets
silently rewritten. That breaks git's literal-bytes contract for messages
(the same contract issue #3 is about, at the message level).

Severity: medium-high — silent content rewrite, machine-state-dependent
(only fires when the converted path exists).

Minimal repro (current shipped build, argv fed directly, no shell)

$ git commit -q --allow-empty -m /c         # stored message: c:/          (should be /c)
$ git commit -q --allow-empty -m /c/Windows # stored message: c:/Windows    (should be /c/Windows)
$ git tag -a -m /c v1                       # annotation body: c:/          (should be /c)
$ git commit -q --allow-empty -m /zz/nosuch # stored message: /zz/nosuch    (OK — converted path absent)

Machine-dependence example observed during the audit: -m /d is preserved on
this machine only because D:\d happens to exist (so the literal lookup
succeeds and the patch keeps the original); on a machine without D:\d, the
same command stores d:/. Message bytes should never depend on what
directories happen to exist on the build/user machine.

Mechanism (patch 0002, wmain argv loop)

for (i = 0; i < argc; i++) {
    /* skip argv[0]: never rewrite the program name */
    const wchar_t *warg = i ? maybe_convert_posix_path_arg(wargv[i])
                            : wargv[i];
    ...
}

maybe_convert_posix_path_arg() rewrites when:

  1. the whole arg matches ^/[A-Za-z](:?/|$) (single leading letter), and
  2. the literal does not exist, but the converted x:/... form does.

No check of whether the position is a pathspec/path-option value or a message
payload.

Impact scope

  • commit -m, commit --amend -m, tag -m, notes -m, replace -m —
    message payloads rewritten.
  • Config values, grep patterns, etc. are mostly safe in practice only by
    accident of the shape check (multi-word values don't match; e.g.
    config test.comment '/c note' survives because the token contains a
    space).

Fix direction (for the pre-release pass)

Keep the conversion as an explicit, narrow feature:

  • never rewrite the value of message options: skip conversion when the
    previous argv element is -m or --message (the --message=<x> /
    -m<x> attached forms are single tokens starting with - and can never
    match the shape check anyway);
  • -F/--file values are file paths and keep benefiting from the
    exists-checked conversion (git commit -F /d/msg.txt works and should
    stay working);
  • everything else keeps the existing double exists-check safety net.

Differential evidence

command shipped wrapper stack shipped real (mingw64) expected (upstream semantics)
commit -m /c c:/ c:/ /c
commit -m /c/Windows c:/Windows c:/Windows /c/Windows
tag -a -m /c c:/ c:/ /c
commit -m /zz/nosuch /zz/nosuch /zz/nosuch /zz/nosuch
commit -F /d/.../msg.txt works works works (keep)
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions