Skip to content

[parser] Bool long options silently accept --flag=value (and grep --count=x hangs) #1301

Closed

Description

@caomengxuan666

Summary

The shared option parser accepts a value on Bool (flag) long options and silently discards it. GNU getopt_long rejects this with option '--x' doesn't allow an argument. Affects every command's every Bool long option. One instance is worse than silent: grep --count=x hangs indefinitely.

Evidence (same-source harness under Wine vs local GNU, two runs each)

  • cat --show-ends=foo file
    • GNU: cat: option '--show-ends' doesn't allow an argument + Try line, exit 1, no output.
    • WinuxCmd: exit 0, prints file with $ line endings (flag applied, value dropped).
  • grep --count=x file
    • GNU: grep: option '--count' doesn't allow an argument + Usage line, exit 2 immediately.
    • WinuxCmd: no output, never returns (killed after 60 s timeout).
  • ls --all=x dir
    • GNU: same form of error, exit 2.
    • WinuxCmd: exit 0, lists normally.
  • cat --help=foo
    • GNU: cat: option '--help' doesn't allow an argument, exit 1.
    • WinuxCmd: cat: unrecognized option '--help' (different failure, because --help/--version are not in the per-command meta and the dispatcher only matches the exact token).

Source

src/core/opt.cppm long-Bool branch (~L262-264) never checks has_inline_value; the single-dash-long branch (~L370-372) has the same shape. The grep hang likely follows from the mis-parse leaving grep waiting on stdin.

Regression seed

  • cat --show-ends=foo f → expect GNU stderr + rc1, empty stdout.
  • grep --count=x f → expect GNU stderr + rc2, returns immediately.
  • ls --all=x . → expect rc2.

Found by the full-audit (argument-form deep audit). Behavior verified against GNU coreutils on identical fixtures; expectations follow GNU.

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

Metadata

Metadata

Labels

bugcompat-gap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions