bugfindutils - Bugs: bug #3992, xargs leaves stdin open and...


bug #3992: xargs leaves stdin open and unchanged

Submitter:  Egmont Koblinger <egmont>
Submitted:  Mon 16 Jun 2003 10:43:31 AM UTC
Category:  xargs Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  None Fixed Release:  4.2.0
* Mandatory Fields

Add a New Comment Rich Markup

Sat 03 Jan 2004 10:56:09 PM UTC, comment #1: 

This problem is fixed in the CVS code for findutils.
To resolve your problem, you could either wait for the
next official release of findutils, or check out a copy
of the code from the CVS repository for findutils.

James Youngman <jay>
Group administrator
Mon 16 Jun 2003 10:43:31 AM UTC, original submission:  

xargs passes its stdin unchanged to the process
it launches. This way if xargs hasn't read all of
its input yet but has already launched a child
(e.g. -n 1 was given) then this child can cause
xargs itself to malfunction if it starts to read
from this file (which is usually a pipe).

Suggested solution: after forking, before execing,
xargs chould connect /dev/null to file desc 0.
This protetcts the real stdin of xargs from being
read by a malicious child.

How to test the buggy behaviour:

Write a script called foobar:
echo "_ $@"
give exec perms, put in path, and then:
{ for i in `seq 1 10`; do echo $i; sleep 1; done; } | xargs -n 1 foobar

Output should be (and without that sleep the output is):
and so on

However, with that sleep, the output is:
_ 1
_ 2
_ 3
which clearly shows that "cat" steals input from
xargs. xargs launches foobar only three times,
though it should do it 10 times.

Tested with version 4.1.7 and 4.1.20.

Egmont Koblinger <egmont>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


CC list is empty


There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.


Follow 3 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2004-10-16 jay Open/ClosedOpen Closed
    Fixed ReleaseNone 4.2.0
2004-01-03 jay StatusNone Fixed

Back to the top

Powered by Savane 3.13-a0c1.
Corresponding source code