From roberte@ghost.mep.ruhr-uni-bochum.de  Wed Mar 12 16:23:16 1997
Received: from ghost.mep.ruhr-uni-bochum.de (ghost.mep.ruhr-uni-bochum.de [134.147.6.16])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id QAA21654
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Mar 1997 16:21:00 -0800 (PST)
Received: (from roberte@localhost)
          by ghost.mep.ruhr-uni-bochum.de (8.8.4/8.8.4)
	  id BAA04142; Thu, 13 Mar 1997 01:19:29 +0100 (CET)
Message-Id: <199703130019.BAA04142@ghost.mep.ruhr-uni-bochum.de>
Date: Thu, 13 Mar 1997 01:19:29 +0100 (CET)
From: Robert Eckardt <roberte@MEP.Ruhr-Uni-Bochum.de>
Reply-To: roberte@MEP.Ruhr-Uni-Bochum.de
To: FreeBSD-gnats-submit@freebsd.org
Subject: csh and/or builtin printf has problems with embedded commands
X-Send-Pr-Version: 3.2

>Number:         2969
>Category:       bin
>Synopsis:       csh and/or builtin printf has problems with embedded commands
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 12 16:30:01 PST 1997
>Closed-Date:    Mon Jul 27 14:33:44 PDT 1998
>Last-Modified:  Mon Jul 27 14:34:52 PDT 1998
>Originator:     Robert Eckardt
>Release:        FreeBSD 2.2-BETA_A i386
>Organization:
Home sweet home
>Environment:

	FreeBSD-2.2 with X11R6-3.2

>Description:

	printf with a shell command as its argument
	prints wrong results. Happens only for builtin printf
	in /usr/bin/csh.

>How-To-Repeat:

	ghost: {1} wc -l fonts.scale | cut -c-9
	     105
	ghost: {2} printf '%d\n' 105
	105
	ghost: {3} printf '%d\n' `wc -l fonts.scale | cut -c-9`
	96
	ghost: {4} /usr/bin/printf '%d\n' `wc -l fonts.scale | cut -c-9`
	105

>Fix:
	
	???

>Release-Note:
>Audit-Trail:

From: Gareth McCaughan <gjm11@dpmms.cam.ac.uk>
To: freebsd-bugs@freebsd.org
Cc:  Subject: Re: bin/2969: csh and/or builtin printf has problems with embedded commands 
Date: Fri, 14 Mar 1997 09:34:33 +0000

 Robert Eckard wrote:
 
 > 	printf with a shell command as its argument
 > 	prints wrong results. Happens only for builtin printf
 > 	in /usr/bin/csh.
 
 What's actually happening is that the csh built-in printf isn't
 expanding its arguments. The "printf" builtin isn't actually
 documented in the manpage (!), but this sounds like a bug since
 it presumably is meant to behave like /usr/bin/printf.
 
 I believe that the following patch fixes the problem.
 
 ---------- patch begins ----------
 *** func.c.orig	Thu Mar 13 19:04:20 1997
 --- func.c	Fri Mar 14 09:27:40 1997
 ***************
 *** 1489,1497 ****
 --- 1489,1510 ----
       Char **v;
       struct command *t;
   {
 +     Char **newv;
       char **c;
       extern int progprintf __P((int, char **));
       int ret;
 + 
 +     gflag = 0;
 +     tglob(v);
 +     if (gflag) {
 + 	newv = globall(v);
 + 	if (newv == 0) {
 + 	    stderror(ERR_NAME | ERR_NOMATCH);
 + 	    return;
 + 	}
 + 	v = newv;
 + 	gargv=0;
 +     }
   
       ret = progprintf(blklen(v), c = short2blk(v));
       (void) fflush(cshout);
 ----------- patch ends -----------
 
 Incidentally, there is a memory leak somewhere around here in csh.
 (The arguments to "doprintf" aren't getting freed.) I'm not suggesting
 a fix because I really don't want to have to read the code carefully
 enough to be sure I wouldn't introduce a bug that freed things twice.
 
 >From a cursory look at the code I suspect that there are in fact
 about 100000 memory leaks of this kind. Yeeuch.
 
 -- 
 Gareth McCaughan       Dept. of Pure Mathematics & Mathematical Statistics,
 gjm11@dpmms.cam.ac.uk  Cambridge University, England.
State-Changed-From-To: open->closed 
State-Changed-By: nectar 
State-Changed-When: Mon Jul 27 14:33:44 PDT 1998 
State-Changed-Why:  
fixed in -CURRENT, rev 1.11 of csh/func.c 
>Unformatted:
