Skip to content

rejects a -NUM context shorthand bundled onto short options that GNU accepts #68

Description

@sylvestre

grep - rejects a -NUM context shorthand bundled onto short options that GNU accepts

Found by the differential fuzzer with args
grep ["-e", "a", "-w44ov", "-B", "1", "--null-data", "-A", "3"].

GNU grep treats a digit run inside a short-option cluster as the -NUM context shorthand:
-w2 means -w -2 (word match with two lines of context), and -w44ov means
-w -4 -4 -o -v. uu_grep only recognizes -NUM as a standalone argument, so it rejects the
bundled form with a parse error and exits 2 where GNU succeeds and exits 0.

Reproduction

Rust (incorrect)

$ printf 'x\ny\n' | ./target/release/grep -w2 x
# Output: (none)
# Stderr: error: unexpected argument '-2' found
# Exit code: 2

GNU (correct)

$ printf 'x\ny\n' | LC_ALL=C /usr/bin/grep -w2 x
# Output: (matching lines with context)
# Exit code: 0

The same happens with any short flag followed by digits, e.g. -i2:

$ printf 'x\ny\n' | ./target/release/grep -i2 x     # Rust: exit 2, "unexpected argument '-2'"
$ printf 'x\ny\n' | LC_ALL=C /usr/bin/grep -i2 x    # GNU:  exit 0

A standalone -2 already works in both (grep -2 x), so the gap is specific to the bundled
form.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions