NetBSD Problem Report #17826

Received: (qmail 15150 invoked by uid 605); 3 Aug 2002 22:22:28 -0000
Message-Id: <200208032222.g73MMTi16081@alicante.eecs.harvard.edu>
Date: Sat, 3 Aug 2002 18:22:29 -0400 (EDT)
From: dholland@eecs.harvard.edu
Sender: gnats-bugs-owner@netbsd.org
Reply-To: dholland@eecs.harvard.edu
To: gnats-bugs@gnats.netbsd.org
Subject: {t,}csh backquote/braces expansion bug
X-Send-Pr-Version: 3.95

>Number:         17826
>Category:       bin
>Synopsis:       {t,}csh backquote/braces expansion bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 03 22:23:00 +0000 2002
>Closed-Date:    
>Last-Modified:  Sun Aug 04 19:17:00 +0000 2002
>Originator:     David A. Holland <dholland@eecs.harvard.edu>
>Release:        NetBSD 1.6B
>Organization:
   - David A. Holland / dholland@eecs.harvard.edu
>Environment:

System: NetBSD alicante 1.6B NetBSD 1.6B (ALICANTE) #2: Tue Jul 2 14:12:37 EDT 2002 dholland@alicante:/usr/src/sys/arch/i386/compile/ALICANTE i386
Architecture: i386
Machine: i386
>Description:

If you write a program "foo" that prints

   echo '{'

and then type

   echo `foo`

tcsh incorrectly prints "Missing }."

Similarly, if you have foo print

   echo '{a,b,c}'

tcsh prints "echo 'a' 'b' 'c'".

Observed with:
   tcsh 6.09 for i386-intel-NetBSD
   tcsh 6.10 for i386-intel-linux
   tcsh 6.11 for i386-intel-FreeBSD
and also
   csh from FreeBSD 4.5-RELEASE
   csh from NetBSD 1.6-current

What happens is that globexpand() in sh.glob.c is called to handle the
backquotes, which is correct; however, after expanding the backquotes,
globexpand proceeds to also expand braces, tilde, and some other
things. None of these expansions check for or honor quotes (either
single or double quotes) and this produces the problem.

I don't claim to know enough about the inner workings of expansions in
csh to suggest a correct fix. Probably the results of backquote
expansion need to be rescanned for quotes earlier than they are.
(They apparently are at some point, although I haven't found the code
yet.)

This problem gets tickled when using the X11 "resize" command in
connection with a termcap entry that contains braces, as some do, but
is more or less silent as long as the braces match, which generally in
the past they have. (However, FreeBSD seems to have recently introduced
an xterm termcap entry where the braces don't match. This broke my
login and caused me to investigate.)

The problem also affects FreeBSD and NetBSD's /bin/csh and, in fact,
probably every csh. Therefore, copies of this message are being sent
to various additional appropriate places.

>How-To-Repeat:

	As above.

>Fix:

	I don't have one (as noted above).
>Release-Note:
>Audit-Trail:

From: David Laight <david@l8s.co.uk>
To: netbsd-bugs@netbsd.org
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/17826: {t,}csh backquote/braces expansion bug
Date: Sun, 4 Aug 2002 20:18:36 +0100

 > If you write a program "foo" that prints
 > 
 >    echo '{'
 > 
 > and then type
 > 
 >    echo `foo`
 > 
 > tcsh incorrectly prints "Missing }."
 > 
 > Similarly, if you have foo print
 > 
 >    echo '{a,b,c}'
 > 
 > tcsh prints "echo 'a' 'b' 'c'".

 Doesn't csh come with a disclaimer saying that its quoting
 rules are non-obvious and that (from memory) 'although useful
 for an interactive shell, csh isn't robust enough for scripts'.

 It is generally much safer so include the output of `` in ""
 (and most variable substitutions as well).

 so
 	echo "`foo`"
 is much safer.

 	David

 -- 
 David Laight: david@l8s.co.uk
>Unformatted:
 	This is -current from 20020627.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.