Skip to content

The Wait-Loop Bound Check Counts a Comparison Bash Never Evaluates #2058

Closed as not planned

Description

@ptr727

Problem

gh-write-guard.py requirement 7 allows some unbounded wait loops. In each of them, the comparison that counts as the loop's bound is text bash never evaluates as a test argument. _bound_in_condition reads the shell tokens from POSIX shlex, together with the quote mask, and it accepts that comparison as the bound. Every shape below is allowed on develop at dd4ca98e, and each is a loop that bash runs forever.

Reproduce (constructed)

while [ "$(echo " -lt " x)" ]; do sleep 1; done
while [ "`echo " -lt " x`" ]; do sleep 1; done
while [ x = $'\' ';' -lt $'\' ] ; true; do sleep 1; done
while [ \x`true -lt 5` ]; do sleep 1; done

A # comment after a quoted operator reaches the same result:

while [ -f y ";" # -lt
true; do sleep 1; done

So does a heredoc fed to a shell with an unquoted delimiter. The outer shell unescapes \\ before the inner one parses the body:

bash <<EOF
until [ -e /nonexistent "a\\" ";" -lt 5 ] \\""; do sleep 1; done
EOF

Cause

shlex does not model the parts of bash's reading these shapes rely on:

  • quotes nesting inside a $(, ${, or backtick that opens within double quotes;
  • a backtick glued to a word;
  • $'...', where a backslash escapes a single quote;
  • a # comment;
  • a heredoc body that a shell reads a second time.

The -lt that the check takes as the bound sits inside a substitution, inside a comment, or inside a command name.

Done looks like

Each command above is denied, and a self-test row pins each one. A bounded loop that uses the same constructs outside its condition stays allowed.

Found by the local strict review of the #1998 fix (handoff #2057). That branch keeps these shapes' verdicts at base rather than changing them.

Activity

  1. added
    bug
    agents
    pre-existing
    on Sep 29, 2026
  2. ptr727 commented on Sep 30, 2026

    @ptr727
    OwnerAuthor

    One more shape of the same cause, found by the local strict review of the #2080 fix (handoff #2137): a bash -c or eval payload read a second time. Inside double quotes the outer lex keeps a backslash before a backtick, where bash removes it, so the payload carries \`, the quote-keeping mask marks that token quoted, and the backtick substitution's -lt counts as the bound.

    bash -c "until [ -f x \`[ 1 -lt 2 ]\` ]; do sleep 1; done"
    eval "until [ -f x \`[ 1 -lt 2 ]\` ]; do sleep 1; done"

    Both are allowed and both loop under timeout 3 bash until the timeout ends them. The loop written out with bare backticks is denied. The bash -c form is allowed on develop too, so it predates that fix, and the eval form reaches it once #2080's fix reads eval payloads. Backslash-dollar inside double quotes likely reads the same way.

  3. ptr727 commented on Oct 8, 2026

    @ptr727
    OwnerAuthor

    Declined per #2517, approved by the maintainer, under GOVERNANCE.md "Trust Boundaries and Hardening Effort": The guard backstops an agent's own mistakes, and this is a command shape built to defeat it rather than one an agent session writes, so a miss does not realistically occur. See #2517 for the per-issue reason.

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

    agentsbugpre-existing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions