permit $1, $!, etc. to be nameref’d again ($_ was); spotted by Jb_boin, 10x!

This commit is contained in:
tg
2014-09-03 19:22:51 +00:00
parent 609a89968f
commit 26f15bd938
5 changed files with 28 additions and 13 deletions

19
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.180 2014/06/26 20:36:02 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.181 2014/09/03 19:22:51 tg Exp $");
/*-
* Variables
@ -789,8 +789,22 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
}
/* check target value for being a valid variable name */
ccp = skip_varname(qval, false);
if (ccp == qval)
if (ccp == qval) {
if (ksh_isdigit(qval[0])) {
int c;
if (getn(qval, &c))
goto nameref_rhs_checked;
} else if (qval[1] == '\0') switch (qval[0]) {
case '$':
case '!':
case '?':
case '#':
case '-':
goto nameref_rhs_checked;
}
errorf("%s: %s", var, "empty nameref target");
}
len = (*ccp == '[') ? array_ref_len(ccp) : 0;
if (ccp[len]) {
/*
@ -801,6 +815,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
errorf("%s: %s", qval,
"nameref target not a valid parameter name");
}
nameref_rhs_checked:
/* prevent nameref loops */
while (qval) {
if (!strcmp(qval, tvar))