Skip to content

[bug] Over-lax: empty or comment-only brace-group body accepted (f() {<newline>}, f() {<newline># c<newline>}, { # c }) — GNU: syntax error near '}' #327

Closed

Description

@caomengxuan666

Found by ecosweep3 lane (pure-bash-bible corpus, section 053 'obsolete function declaration'; carrier release build of 6106961). New instance of the over-lax family (#221).

Reproducer matrix (target/probe-out/p13a-d.sh)

f() {
}
echo ok-empty
f() {
# c
}
echo ok-comment
{
# c
}
echo ok-group

GNU bash 5.3.0: ALL THREE are syntax error near unexpected token }`` (rc=2) — a brace group must contain a command list, and a comment is not a command.
rubash: all three accepted and run (rc=0).

Control (both shells agree, rc=2): while false; do\n# c\ndone and if cmd; then\n# c\nfi — so rubash already enforces the rule for loop/if bodies; the { } group case alone is missing.

GNU anchor

parse.y brace_group production requires a list; } only terminates after a nonempty newline_list + command sequence (see parse.y grammar brace_group: '{' newline_list list '}' region and the error_near_token reporting at }). Note rubash's while-body error text also appends a stray ; (done' vs GNU done' — minor wording, same family as #285).

Impact

Scripts relying on the GNU syntax error (typo detection, shellcheck-clean guarded blocks) silently behave differently; corpus-counted as parse over-acceptance in 1 pbb section.

Activity

  1. added
    bug
    gnu-baseline
    on Sep 29, 2026
  2. added a commit that references this issue on Sep 29, 2026
  3. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt14/pbbfix (8738568, master): the brace-group completeness check treated comment-only+newline bodies as complete, and both function-body paths lacked the empty-body check the multi-token path had. { requires a compound_list (parse.y:1196). Also fixed the offending-line echo gluing the newline token synthetic semicolon into the line text (done; -> done). All three reproducers + loop-control cases + inline { } messages/line numbers/rc byte-identical; 12 legal-body scans identical.

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

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions