Skip to content

Read Reassigned Exports, Rerun Exports, and Clustered xargs Options in the Write Guard #3340

Closed

Description

@ptr727

Context

Found by the third local review pass on the change for #3050, #3083, #3085, #3304, and #3307 (branch feature/guard-directory-tokenizer-launchers). Each shape is allowed by develop's guard too, so none is a regression. They are near variants the new readers do not reach, filed under the lane's stop rule rather than narrowed in a third round. Each was confirmed with a classify probe on constructed commands.

Shapes the New Readers Miss

  • A name reassigned after it is exported. _exported_states does not track a plain assignment to an already exported name, which _gh_repo_states does for GH_REPO.
    • cd /example/wt && export GIT_DIR=/example/wt/.git && GIT_DIR=/example/primary/.git && git reset --hard, where /example/primary is a primary checkout
    • cd /example/wt && export GIT_DIR GIT_WORK_TREE; GIT_DIR=/example/primary/.git GIT_WORK_TREE=/example/primary; git reset --hard
  • An export after the git word that a function or loop runs first. _exported_states reads only the words before the git word, where _repo_may_move reads the whole command under _reruns.
    • cd /example/wt && f() { git reset --hard; }; export GIT_DIR=/example/primary/.git; f
    • cd /example/wt && for i in 1 2; do git reset --hard; export GIT_DIR=/example/primary/.git; done
  • A clustered xargs replace option. _xargs_replaces misses -0I{} and -rI{}, and the BSD -J{} spelling.
    • echo 'git config remote.origin.mirror true' | xargs -0I{} sh -c '{}'; git push --tags origin
  • The config scan of a wrapper body skips _string_read_elsewhere. _names_config_change and _config_may_change run separate per-word scans.
    • bash -c "echo 'git config remote.origin.mirror true' | xargs -I{} sh -c '{}'"; git push --tags origin

Possible Direction

Track a reassignment of an exported name as _gh_repo_states does, read the whole command where _reruns says a later word may run first, read xargs's replace option inside a cluster, and share one per-word predicate between the two config scans.

Activity

  1. added
    bug
    introduced
    script
    on Oct 22, 2026
  2. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    Two more near variants from the fourth local pass on #3342, each allowed by develop too:

    • cd /example/wt && set -a && GIT_DIR=/example/primary/.git && git reset --hard, where set -a exports the plain assignment.
    • cd /example/wt && f() { local -x GIT_DIR=/example/primary/.git; git reset --hard; }; f

    The GH_REPO reading already fails closed on set -a.

  3. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    One more near variant from the fifth local pass on #3342, allowed by develop too: an assignment sudo passes behind a launcher the guard does not know, as in uv run sudo GIT_CONFIG_GLOBAL=/example/config git status. Behind such a launcher only an env passes its assignments on, while sudo NAME=value cmd sets the environment as well.

  4. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    Two more from the sixth local pass on #3342, each allowed by develop too:

    • uv run env GH_REPO=stranger/example gh pr comment 5 --body x. The GH_REPO readers take a launcher's prefix in place of the shell's state, so Read Every Launcher and Exported Git Directory in the Write Guard #3342 keeps develop's reading there, with no assignment after an unknown launcher. Reading those values beside the shell's state rather than in place of it would deny this and keep find ./env -name GH_REPO=... -exec gh ... denied.
    • coproc example { "$CMD"; }; git push --tags origin. A run-time command word in a named coproc's group is not read, since the walk stops at the name.
  5. ptr727 commented on Oct 22, 2026

    @ptr727
    OwnerAuthor

    One more from the seventh local pass on #3342, allowed by develop too: cd /example/wt && export GIT_DIR=/example/primary/.git && find ./env -name GIT_DIR=/example/wt/.git -exec git reset --hard \;. _launcher_prefix reads any word whose base name is env as the env command, a path such as ./env included, and _git_dir_rereading lets that prefix override every export state. Reading only an env the launcher runs, or reading the prefix beside each state rather than over it, closes it.

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

    bugintroducedscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions