Skip to content

sed - s///pp (repeated p flag) is accepted instead of rejected #652

Open

Description

@sylvestre

GNU sed rejects an s command that repeats the p flag, with
multiple `p' options to `s' command and exit status 1. uutils sed accepts it and prints the
line. Repeated g and repeated numbers are already rejected with GNU's messages (74f73e0); p
is the remaining case.

Reproduction

Rust (incorrect)

$ printf 'a\n' | ./target/release/sed 's/a/b/pp'
b
b
# Exit code: 0

GNU (correct)

$ printf 'a\n' | /usr/bin/sed 's/a/b/pp'
/usr/bin/sed: -e expression #1, char 8: multiple `p' options to `s' command
# Exit code: 1

Root cause

compile_subst_flags in src/sed/compiler.rs:1027-1032 sets the flag without checking whether
it was already set, unlike the g arm just above it:

'g' => {
    if subst.global {
        return compilation_error(lines, line, "multiple `g' options to `s' command");
    }
    ...
'p' => {
    subst.print_flag = true;
    // 'p' is applied before 'e' iff 'e' has not been seen yet.
    subst.p_before_e = !subst.execute;
    line.advance();
}

Test

#[rstest]
#[case::adjacent("s/a/b/pp")]
#[case::separated("s/a/b/pgp")]
fn test_subst_repeated_p_flag_rejected(#[case] script: &str) {
    new_ucmd!()
        .arg(script)
        .pipe_in("a\n")
        .fails()
        .code_is(1)
        .stderr_contains("multiple `p' options to `s' command");
}

Reported by Anthropic's OSS Scanner (ANT-2026-FNVSC9N4).

Activity

  1. added
    bug
    good first issue
    oss-scanner
    gnu-compat
    on Nov 9, 2026
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-compatgood first issueoss-scanner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions