Date: Fri, 24 May 1996 12:28:32 -0500 (CDT) From: fredriks@mcs.com To: FreeBSD-gnats-submit@freebsd.org Subject: bin/1248: shell having problem parsing arguments Message-ID: <199605241728.MAA12700@fredriks.pr.mcs.net> Resent-Message-ID: <199605250350.UAA03865@freefall.freebsd.org>
index | next in thread | raw e-mail
>Number: 1248
>Category: bin
>Synopsis: /bin/sh has trouble with arguments past 9(ie. ${10})
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri May 24 20:50:02 PDT 1996
>Last-Modified:
>Originator: Lars Fredriksen
>Organization:
Flaaklypa Hackers
>Release: FreeBSD 2.2-CURRENT i386
>Environment:
FreeBSD 2.2-CURRENT as of 5/23/96 (sup and compile)
>Description:
/bin/sh has a couple of bugs when dealing with arguments past
argument #9. First off you get a syntax error when it tries
to parse ${11}, enclosed is fix for the parser. The second
problem is that the setting and retrieving of variables did
not handle anything past 9 arguments. The fix is in expand.c
and is included below. Please test and review these. The
fixes seem to work on the stuff I have tested, but I do not
claim to have done a complete regression test on the sh.
I do have commit priviledges so I can do the commits, but
I need someone to review this. The same goes for kern/1245!
>How-To-Repeat:
>Fix:
Index: parser.c
===================================================================
RCS file: /home/ncvs/src/bin/sh/parser.c,v
retrieving revision 1.11
diff -r1.11 parser.c
1111,1112c1111,1120
< USTPUTC(c, out);
< c = pgetc();
---
>
> if (is_digit(c)) {
> do {
> STPUTC(c, out);
> c = pgetc();
> } while( is_digit(c));
> } else {
> USTPUTC(c, out);
> c = pgetc();
> }
Index: expand.c
===================================================================
RCS file: /home/ncvs/src/bin/sh/expand.c,v
retrieving revision 1.4
diff -r1.4 expand.c
93,94c93,94
< STATIC int varisset(int);
< STATIC void varvalue(int, int, int);
---
> STATIC int varisset(char *);
> STATIC void varvalue(char *, int, int);
456c456
< set = varisset(*var);
---
> set = varisset(var);
470c470
< varvalue(*var, varflags & VSQUOTE, flag & EXP_FULL);
---
> varvalue(var, varflags & VSQUOTE, flag & EXP_FULL);
542c542
< char name;
---
> char *name;
543a544,545
> char *t;
> int numvar;
546c548
< if (name == '!') {
---
> if (*name == '!') {
549c551
< } else if (name == '@' || name == '*') {
---
> } else if (*name == '@' || *name == '*') {
552,557c554,568
< } else if ((unsigned)(name -= '1') <= '9' - '1') {
< ap = shellparam.p;
< do {
< if (*ap++ == NULL)
< return 0;
< } while (--name >= 0);
---
> } else {
> t = name;
> while (is_digit(*t++)) {
> ;
> }
>
> if ( *--t == '=' ) {
> *t = '\0';
> numvar = atoi(name);
> ap = shellparam.p;
> do {
> if (*ap++ == NULL)
> return 0;
> } while (--numvar > 0);
> }
570c581
< char name;
---
> char *name;
572a584
> int numvar;
574a587
> char *t;
596c609
< switch (name) {
---
> switch (*name) {
643,644c656,663
< if ((unsigned)(name -= '1') <= '9' - '1') {
< p = shellparam.p[name];
---
>
> t = name;
> while (is_digit(*t++)) {
> }
>
> if ( *t == '\0' ) {
> numvar = atoi(name);
> p = shellparam.p[numvar-1];
>Audit-Trail:
>Unformatted:
>Repeat-By:
JUNK="1 2 3 4 5 6 7 8 9 10 11 12"
set $JUNK
echo ${11}
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605241728.MAA12700>
