Subject: bin/17826: {t,}csh backquote/braces expansion bug
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dholland@eecs.harvard.edu>
List: netbsd-bugs
Date: 08/03/2002 18:22:29
>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 15:23:00 PDT 2002
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
 	This is -current from 20020627.