Skip to content

rejects a leading quantifier (?/*/+) that GNU accepts with a warning #23

Closed

Description

@sylvestre

A repetition operator (?, *, +) at the start of an expression has no preceding atom to repeat. GNU grep treats this leniently: it prints warning: <op> at start of expression to stderr, matches as if the operator were a no-op (so every line is selected), and exits 0. uu_grep rejects the pattern as a hard error and exits 2.

Found by the differential fuzzer (fuzz_grep).

Rust (incorrect)

$ printf 'abc\n' | ./target/release/grep -e '?' -E
# Output (stderr): grep: invalid pattern "?": Oniguruma error: target of repeat operator is not specified
# Exit code: 2

GNU (correct)

$ printf 'abc\n' | LC_ALL=C /usr/bin/grep -e '?' -E
# Output (stderr): grep: warning: ? at start of expression
# Output (stdout): abc
# Exit code: 0

The same divergence occurs for * and + as the leading character (grep -E '*', grep -E '+'): GNU warns and matches every line (exit 0); uu_grep errors (exit 2).

Activity

  1. sylvestre commented on Jun 4, 2026

    @sylvestre
    SponsorContributorAuthor

    The interval form {2} triggers the same thing — GNU warns {...} at start of expression and matches every line, uu_grep errors:

    $ printf 'abc\n' | LC_ALL=C /usr/bin/grep -E '{2}'   # warning: {...} at start of expression; matches; exit 0
    $ printf 'abc\n' | ./target/release/grep -E '{2}'    # invalid pattern error; exit 2
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

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions