experimental diff:

From: Todd C. Miller <Todd.Miller@courtesan.com>
The following ksh diff needs wide testing.  It does the following:
 1) proper error message for bad substitution.
    Before:
        $ echo ${a[@]:foo}
        ksh: : bad substitution
    After:
        $ echo ${a[@]:foo}
        ksh: ${a[@]:foo}: bad substitution
 2) fix a core dump for "echo ${a[@]:?foo}".
 3) fix a use-after-free bug (from otto@)
This commit is contained in:
tg
2004-12-10 22:21:26 +00:00
parent e2c4bce569
commit 8a1afa6087
7 changed files with 42 additions and 40 deletions

9
eval.c
View File

@ -1,4 +1,4 @@
/** $MirBSD: eval.c,v 1.10 2004/12/10 16:01:34 tg Exp $ */
/** $MirBSD: eval.c,v 1.11 2004/12/10 22:21:25 tg Exp $ */
/* $OpenBSD: eval.c,v 1.16 2004/12/08 21:23:18 millert Exp $ */
/*
@ -10,7 +10,7 @@
#include "ksh_dir.h"
#include "ksh_stat.h"
__RCSID("$MirBSD: eval.c,v 1.10 2004/12/10 16:01:34 tg Exp $");
__RCSID("$MirBSD: eval.c,v 1.11 2004/12/10 22:21:25 tg Exp $");
/*
* string expansion
@ -287,12 +287,12 @@ expand(char *cp, XPtrV *wp, int f)
char endc;
char *str, *end;
sp = varname - 2; /* restore sp */
end = (char *) wdscan(sp, CSUBST);
/* ({) the } or x is already skipped */
endc = *end;
*end = EOS;
str = snptreef((char *) 0, 64, "%S",
varname - 1);
str = snptreef(NULL, 64, "%S", sp);
*end = endc;
errorf("%s: bad substitution", str);
}
@ -801,6 +801,7 @@ varsub(Expand *xp, char *sp, char *word, int *stypep, int *slenp)
case '=': /* can't assign to a vector */
case '%': /* can't trim a vector (yet) */
case '#':
case '?':
return -1;
}
XPinit(wv, 32);