Skip to content

xargs - -E '' sets an empty EOF string instead of disabling it #971

Closed

Description

@sylvestre

POSIX says: "When eofstr is the null string, the logical end-of-file string capability
shall be disabled." GNU xargs follows this. uutils xargs instead installs "" as the
end-of-file marker. In the default input mode, the first item that unquotes to nothing
('' or "") silently ends the input, so every later item is dropped and the exit status
is 0.

Reproduction

Rust (incorrect)

$ printf "a\n''\nb\nc\n" | ./target/release/xargs -E '' printf '[%s]'
[a]
# Exit code: 0

GNU (correct)

$ printf "a\n''\nb\nc\n" | /usr/bin/xargs -E '' printf '[%s]'
[a][][b][c]
# Exit code: 0

Without -E, uutils already prints [a][][b][c].

Root cause

do_xargs in src/xargs/mod.rs:1211-1217 keeps any value it receives, including an empty
one:

eof_delimiter: [options::EOF_E, options::EOF].iter().find_map(|&option| {
    matches.contains_id(option).then(|| {
        matches
            .get_one::<String>(option)
            .map_or_else(|| "{}".to_string(), std::borrow::ToOwned::to_owned)
    })
}),

Some("") then reaches EofArgumentReader::new (line 1269), which stops at the first item
equal to "".

Test

In tests/test_xargs.rs, next to xargs_eof:

#[test]
fn xargs_empty_eof_string_disables_eof() {
    ucmd()
        .args(&["-E", "", "echo"])
        .pipe_in("one\n\"\"\ntwo three\n")
        .succeeds()
        .stdout_only("one  two three\n");
}

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

Activity

  1. added
    oss-scanner
    gnu-compat
    on Nov 9, 2026
  2. added a commit that references this issue on Nov 10, 2026
    56759c5
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