prevent indirect recursion loops for namerefs; found by ormaaj, thanks!

This commit is contained in:
tg 2013-05-31 22:47:14 +00:00
parent 407734d305
commit 21ee1a8411
2 changed files with 17 additions and 10 deletions

12
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.612 2013/05/02 21:59:45 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.613 2013/05/31 22:47:12 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R46 2013/05/02 @(#)MIRBSD KSH R46 2013/05/31
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R46 2013/05/02 @(#)LEGACY KSH R46 2013/05/31
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:
@ -10261,7 +10261,7 @@ description:
time-limit: 3 time-limit: 3
stdin: stdin:
baz() { baz() {
typeset -n foo=foo typeset -n foo=fnord fnord=foo
foo[0]=bar foo[0]=bar
} }
set -A foo bad set -A foo bad
@ -10270,7 +10270,9 @@ stdin:
echo blah $foo . echo blah $foo .
expected-stdout: expected-stdout:
sind bad . sind bad .
blah bar . blah bad .
expected-stderr-pattern:
/fnord: expression recurses on parameter/
--- ---
name: better-parens-1a name: better-parens-1a
description: description:

15
var.c
View File

@ -27,7 +27,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.172 2013/05/02 20:23:09 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.173 2013/05/31 22:47:14 tg Exp $");
/*- /*-
* Variables * Variables
@ -768,10 +768,15 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
if (vp != NULL) if (vp != NULL)
qval = str_val(vp); qval = str_val(vp);
} }
/* silently ignore 'nameref foo=foo' */ /* prevent nameref loops */
if (qval != NULL && !strcmp(qval, tvar)) { while (qval) {
afree(tvar, ATEMP); if (!strcmp(qval, tvar))
return (&vtemp); errorf("%s: %s", qval,
"expression recurses on parameter");
varsearch(e->loc, &vp, qval, hash(qval));
qval = NULL;
if (vp && ((vp->flag & (ARRAY|ASSOC)) == ASSOC))
qval = str_val(vp);
} }
} }