From nobody@FreeBSD.org  Sat Sep  3 18:03:07 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7D43816A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  3 Sep 2005 18:03:07 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 4CC6B43D45
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  3 Sep 2005 18:03:07 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j83I37ne030640
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 3 Sep 2005 18:03:07 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j83I36VM030639;
	Sat, 3 Sep 2005 18:03:06 GMT
	(envelope-from nobody)
Message-Id: <200509031803.j83I36VM030639@www.freebsd.org>
Date: Sat, 3 Sep 2005 18:03:06 GMT
From: Rici Lake <rici@ricilake.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: xargs -E doesn't work
X-Send-Pr-Version: www-2.3

>Number:         85696
>Category:       bin
>Synopsis:       xargs -E doesn't work
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 03 18:10:10 GMT 2005
>Closed-Date:    Sat Dec 31 01:07:37 PST 2005
>Last-Modified:  Sat Dec 31 01:07:37 PST 2005
>Originator:     Rici Lake
>Release:        5.2; 4.10
>Organization:
Oxfam
>Environment:
>Description:
The -E argument to xargs does not work unless MALLOC_OPTIONS have been set to zero memory.
>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


>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';

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jmallett 
State-Changed-When: Sat Dec 31 01:07:19 PST 2005 
State-Changed-Why:  
Checked in a fix, let me know if you experience any problems. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85696 
>Unformatted:
