limit alias characters to what POSIX requires

This commit is contained in:
tg 2017-04-06 00:53:35 +00:00
parent bcde17a8fc
commit e00f693cba
3 changed files with 16 additions and 4 deletions

10
funcs.c
View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.334 2017/04/02 16:47:41 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.335 2017/04/06 00:53:33 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -839,6 +839,14 @@ c_alias(const char **wp)
strndupx(xalias, alias, val++ - alias, ATEMP); strndupx(xalias, alias, val++ - alias, ATEMP);
alias = xalias; alias = xalias;
} }
newval = alias;
while (*newval)
if (!ksh_isalias(*newval)) {
bi_errorf(Tinvname, alias, Talias);
afree(xalias, ATEMP);
return (1);
} else
++newval;
h = hash(alias); h = hash(alias);
if (val == NULL && !tflag && !xflag) { if (val == NULL && !tflag && !xflag) {
ap = ktsearch(t, alias, h); ap = ktsearch(t, alias, h);

6
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.437 2017/04/03 02:10:49 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.438 2017/04/06 00:53:33 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"- .\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -76,7 +76,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to .\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always. .\" use our own definition. And .Dd must come *first*, always.
.\" .\"
.Dd $Mdocdate: April 3 2017 $ .Dd $Mdocdate: April 6 2017 $
.\" .\"
.\" Check which macro package we use, and do other -mdoc setup. .\" Check which macro package we use, and do other -mdoc setup.
.\" .\"
@ -3063,6 +3063,8 @@ For any name without a value, the existing alias is listed.
Any name with a value defines an alias (see Any name with a value defines an alias (see
.Sx Aliases .Sx Aliases
above). above).
.Li \&[A\-Za\-z0\-9_!%,@]
are valid in names.
.Pp .Pp
When listing aliases, one of two formats is used. When listing aliases, one of two formats is used.
Normally, aliases are listed as Normally, aliases are listed as

4
sh.h
View File

@ -175,7 +175,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.803 2017/04/06 00:41:42 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.804 2017/04/06 00:53:35 tg Exp $");
#endif #endif
#define MKSH_VERSION "R54 2017/04/02" #define MKSH_VERSION "R54 2017/04/02"
@ -1276,6 +1276,8 @@ extern unsigned char chtypes[];
#define ctype(c, t) tobool(chtypes[(unsigned char)(c)] & (t)) #define ctype(c, t) tobool(chtypes[(unsigned char)(c)] & (t))
#define ord(c) ((int)(unsigned char)(c)) #define ord(c) ((int)(unsigned char)(c))
#define ksh_issubop2(c) tobool((c) == ord('#') || (c) == ord('%')) #define ksh_issubop2(c) tobool((c) == ord('#') || (c) == ord('%'))
#define ksh_isalias(c) (ctype((c), C_ALPHX | C_DIGIT) || (c) == ord('!') || \
(c) == ord('%') || (c) == ord(',') || (c) == ord('@'))
#define ksh_isalpha(c) (ctype((c), C_ALPHX) && (c) != ord('_')) #define ksh_isalpha(c) (ctype((c), C_ALPHX) && (c) != ord('_'))
#define ksh_isalphx(c) ctype((c), C_ALPHX) #define ksh_isalphx(c) ctype((c), C_ALPHX)
#define ksh_isalnux(c) ctype((c), C_ALPHX | C_DIGIT) #define ksh_isalnux(c) ctype((c), C_ALPHX | C_DIGIT)