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

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.663 2014/07/04 11:03:52 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.664 2014/09/03 19:22:48 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014 # 2011, 2012, 2013, 2014
@ -1784,7 +1784,7 @@ else
#define EXTERN #define EXTERN
#define MKSH_INCLUDES_ONLY #define MKSH_INCLUDES_ONLY
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.663 2014/07/04 11:03:52 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.664 2014/09/03 19:22:48 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (isatty(0)); } int main(void) { printf("Hello, World!\n"); return (isatty(0)); }
EOF EOF
case $cm in case $cm in
@ -2310,7 +2310,7 @@ addsrcs '!' HAVE_STRLCPY strlcpy.c
addsrcs USE_PRINTF_BUILTIN printf.c addsrcs USE_PRINTF_BUILTIN printf.c
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose" test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
add_cppflags -DMKSH_BUILD_R=501 add_cppflags -DMKSH_BUILD_R=502
$e $bi$me: Finished configuration testing, now producing output.$ao $e $bi$me: Finished configuration testing, now producing output.$ao

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.135 2014/06/24 20:47:42 tg Exp $ # $MirOS: src/bin/mksh/Makefile,v 1.136 2014/09/03 19:22:48 tg Exp $
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014 # 2011, 2012, 2013, 2014
@ -55,7 +55,7 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \ -DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 \
-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \ -DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \ -DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
-DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=501 -DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=502
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U} CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
CPPFLAGS+= -I. CPPFLAGS+= -I.
COPTS+= -std=c89 -Wall COPTS+= -std=c89 -Wall

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.657 2014/07/29 17:56:31 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.658 2014/09/03 19:22:49 tg Exp $
# OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44 # OpenBSD src/regress/bin/ksh updated: 2013/12/02 20:39:44
#- #-
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
@ -27,7 +27,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 R50 2014/07/28 @(#)MIRBSD KSH R50 2014/09/03
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -36,7 +36,7 @@ name: KSH_VERSION
category: shell:legacy-no category: shell:legacy-no
--- ---
expected-stdout: expected-stdout:
@(#)LEGACY KSH R50 2014/07/28 @(#)LEGACY KSH R50 2014/09/03
description: description:
Check version of legacy shell. Check version of legacy shell.
stdin: stdin:

6
sh.h
View File

@ -169,9 +169,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.693 2014/07/28 21:45:45 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.694 2014/09/03 19:22:50 tg Exp $");
#endif #endif
#define MKSH_VERSION "R50 2014/07/28" #define MKSH_VERSION "R50 2014/09/03"
/* arithmetic types: C implementation */ /* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES #if !HAVE_CAN_INTTYPES
@ -533,7 +533,7 @@ char *ucstrstr(char *, const char *);
#define mkssert(e) do { } while (/* CONSTCOND */ 0) #define mkssert(e) do { } while (/* CONSTCOND */ 0)
#endif #endif
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 501) #if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 502)
#error Must run Build.sh to compile this. #error Must run Build.sh to compile this.
extern void thiswillneverbedefinedIhope(void); extern void thiswillneverbedefinedIhope(void);
int int

19
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #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 * 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 */ /* check target value for being a valid variable name */
ccp = skip_varname(qval, false); 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"); errorf("%s: %s", var, "empty nameref target");
}
len = (*ccp == '[') ? array_ref_len(ccp) : 0; len = (*ccp == '[') ? array_ref_len(ccp) : 0;
if (ccp[len]) { 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, errorf("%s: %s", qval,
"nameref target not a valid parameter name"); "nameref target not a valid parameter name");
} }
nameref_rhs_checked:
/* prevent nameref loops */ /* prevent nameref loops */
while (qval) { while (qval) {
if (!strcmp(qval, tvar)) if (!strcmp(qval, tvar))