Bug 85696 - xargs -E doesn't work
Summary: xargs -E doesn't work
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-03 19:10 UTC by Rici Lake
Modified: 2005-12-31 09:07 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rici Lake 2005-09-03 19:10:10 UTC
The -E argument to xargs does not work unless MALLOC_OPTIONS have been set to zero memory.

Fix: 

Lines 293-298 of xargs.c (revision 1.55.2.1)
The test at line 295 is testing the buffer currently being constructed with the -E option argument (eofstr). Since the buffer has not been NUL-terminated, this will only produce the correct answer by accident (indeed, it could run off and read unallocated memory if the -E string were long enough)

*p should zapped before the compare is done, rather than at line 299. (Although I haven't traced through the execution path in full; I assume zapping *p at this point does no harm, but a full analysis is necessary.)

 293: arg2:
 294:                foundeof = *eofstr != '\0' &&
 295:                    strcmp(argp, eofstr) == 0;
 296:
 297:                /* Do not make empty args unless they are quoted */
 298:                if ((argp != p || wasquoted) && !foundeof) {
 299:                        *p++ = '\0';
How-To-Repeat: This should echo "one"):
echo $'one\ntwo\nthree' | xargs -E two echo

It works with MALLOC_OPTIONS=Z and fails with MALLOC_OPTIONS=J

-bash-2.05b$ echo $'one\ntwo\nthree' | MALLOC_OPTIONS=J xargs -E two echo
one two three
-bash-2.05b$ echo $'one\ntwo\nthree' | MALLOC_OPTIONS=Z xargs -E two echo
one
Comment 1 Juli Mallett freebsd_committer freebsd_triage 2005-12-31 09:07:19 UTC
State Changed
From-To: open->closed

Checked in a fix, let me know if you experience any problems.