csh variable syntax '${x1[2]}' is broken.

Michael Greim greim at sbsvax.UUCP
Mon Apr 10 20:39:48 AEST 1989


In article <1893 at trantor.harris-atd.com>, bbadger at x102c.harris-atd.com (Badger BA 64810) writes:
> Variable expansion in csh isn't done properly.
[...]
You can fix this bug if you have source.
I have published a fix on 12. January 1988. I was relatively new to the net,
so I did not obey some conventions.
This fix is part of a set of fixes. One of the projects I have waiting on
my schedule is to bundle all the fixes, create diffs for the tahoe csh
(which has the same bugs, mostly) and publish all this in the appropriate
news group.
I always wondered who applied my fixes.

= From greim at sbsvax.UUCP Tue Jan 12 19:24:28 1988
= Path: sbsvax!greim
= From: greim at sbsvax.UUCP (Michael Greim)
= Newsgroups: comp.unix.wizards
= Subject: Re: csh oddity
= Summary: fix
= Keywords: csh variables substitution
= Message-ID: <373 at sbsvax.UUCP>
= Date: 12 Jan 88 18:24:28 GMT
= References: <826 at murphy.UUCP>
= Organization: Universitaet des Saarlandes, D-6600 Saarbruecken, FRG
= Lines: 87
= 
= This is in answer to an article by
= Dave Cornutt, Gould Computer Systems, Ft. Lauderdale, FL
= 
= He writes about a bug in csh.
= Doing
=         set a1b=abc
=         set b=${a1b}
= will provoke an error message "Variable syntax.", and in the
= history the last command will be entered as "set b=1${ab}".
= 
= This is really a bug, but it is relativly easy to find and to fix.
= I know some which are very difficult to fix.
= 
= Diagnosis:
=         Look in sh.lex.c, somewhere around line  390 in the routine getdol
=         there should be the following code (this here quoted from 4.3 BSD):
= 
=         case '*':
=                 if (special)
=                         goto vsyn;
=                 goto ret;
= 
=         default:
=                 if (digit(c)) {
= /*
=  * let $?0 pass for now
=                         if (special)
=                                 goto vsyn;
= */
=                         while (digit(c = getC(DOEXCL))) {
=                                 if (np < &name[sizeof name / 2])
=                                         *np++ = c;
=                         }
=                 } else if (letter(c))
=                         while (letter(c = getC(DOEXCL))) {
=                                 if (np < &name[sizeof name / 2])
=                                         *np++ = c;
=                         }
=                 else
=                         goto vsyn;
=         }
= 
=         This code causes the bug. After a $ is encountered the routine looks
=         if a number follows, it was '$1' or something like this, if not,
=         it wants to check whether the variable name is correct, but it
=         only tests if all characters a letters. Variable Names can contain
=         numberes too.
= 
=         Therapy:
=                 change to
= 
=         case '*':
=                 if (special)
=                         goto vsyn;
=                 goto ret;
= 
=         default:
=                 if (digit(c)) {
= /*
=  * let $?0 pass for now
=                         if (special)
=                                 goto vsyn;
= */
=                         while (digit(c = getC(DOEXCL))) {
=                                 if (np < &name[sizeof name / 2])
=                                         *np++ = c;
=                         }
=                 } else if (alnum(c))
=                         while (alnum(c = getC(DOEXCL))) {
=                                 if (np < &name[sizeof name / 2])
=                                         *np++ = c;
=                         }
=                 else
=                         goto vsyn;
=         }
= 
= 
[...]

= From greim at sbsvax.UUCP Mon Jan 18 17:12:59 1988
= Path: sbsvax!greim
= From: greim at sbsvax.UUCP (Michael Greim)
= Newsgroups: comp.unix.wizards,comp.bugs.4bsd
= Subject: Re: csh oddity, fix
= Keywords: csh variables substitution fix
= Message-ID: <374 at sbsvax.UUCP>
= Date: 18 Jan 88 16:12:59 GMT
= Organization: Universitaet des Saarlandes, D-6600 Saarbruecken, FRG
= Lines: 95
= 
= In article <826 at murphy.UUCP> dcornutt at murphy.UUCP (Dave Cornutt) writes:
= > I have discovered something peculiar about csh variable substitution.  Is
= > this a bug or am I doing something wrong?
= 
= Sorry folks,
= The fix I sent on 12. Jan. is not complete. It does not cover every
= instance of the bug.
= Like Chris Torek says in <10167 at mimsy.UUCP> it is idiocy
= for two routines to handle the same job. But it comes even better :
= the test, whether a variable name is valid, is done differently in
= several parts of csh.
= 
= Try the following commands, and note the faulty behaviour
=     set xy1z=mist
= 1.) echo ${xy1z}          in sh.lex.c
= 2.) set 1a                in sh.set.c
= 3.) foreach a1b ...       in sh.func.c
= 
= If I have overlooked a bug instance, tell me. (But apply the fixes first:
= they will kill some bugs :-)
= 
= I do not give any context diff's, because my sourcecode is cluttered
= with ifdef's, so the output might be too confusing. And I am too lazy
= to revert to the original code in SCCS :^o
= 
= The first situation is covered by my fix from 12.Jan, which applied to
= the piece of code Chris Torek (<10167 at mimsy.UUCP>) and Craig Hansen
= (<1326 at mips.UUCP>) suspected.
[...]
= 
= + means new line
= - means deleted line
= ! means changed line
= 
= Fix2:
=         in sh.set.c, routine doset, about line 30
=         ...
=         do {
=                 hadsub = 0;
= +               if (!letter (*p))
= +                       goto setsyn;
=                 for (vp = p; alnum(*p); p++)
=                         continue;
=                 if (vp == p)
=                         goto setsyn;
=         ...
= 
= Fix3:
=         in sh.func.c, routine doforeach, about line 356
=         ...
=         cp = strip(*v);
= +       if (! letter (*cp))
= +               bferr("Variable syntax");
= !       while (*cp && alnum(*cp))
=                 cp++;
=         if (*cp || strlen(*v) >= 20)
=                 bferr("Invalid variable");
=         ...
= 
[...]

Absorb, apply and enjoy,
	-mg

email : greim at sbsvax.informatik.uni-saarland.dbp.de
  (some mailers might not like this. Then use greim at sbsvax.uucp)
  or  : ...!uunet!unido!sbsvax!greim
# include <disclaimers/std.h>
-- 
email : greim at sbsvax.informatik.uni-saarland.dbp.de
  (some mailers might not like this. Then use greim at sbsvax.uucp)
  or  : ...!uunet!unido!sbsvax!greim
# include <disclaimers/std.h>



More information about the Comp.unix.wizards mailing list