From 6697edba1c302c4bdd0796945158decc825b5bd5 Mon Sep 17 00:00:00 2001 From: hyenias <58673227+hyenias@users.noreply.github.com> Date: Sun, 4 Oct 2020 05:18:34 -0400 Subject: [PATCH] Enforce integer base limits of 2 to 64 (#139) src/cmd/ksh93/bltins/typeset.c: b_typeset(): - For integer bases change argnum check to default values that are < 2 or > 64 to 10 instead of allowing invalid base values that ksh cannot process. src/cmd/ksh93/bltins/typeset.c: setall(): - Remove argnum check for integer base of 1 as base cannot be 1. - Relocate strlen(name) to inside of conditional check for np->nvfun as this code does not need to run all. - Remove no-op oldname code src/cmd/ksh93/tests/attributes.sh: - Add typeset -i base bounds checks to default base 10 --- src/cmd/ksh93/bltins/typeset.c | 10 ++-------- src/cmd/ksh93/tests/attributes.sh | 8 ++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index c013510dd..eca594f46 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -320,7 +320,7 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) troot = tdata.sh->fun_tree; break; case 'i': - if(!opt_info.arg || (tdata.argnum = opt_info.num) <0) + if(!opt_info.arg || (tdata.argnum = opt_info.num) <2 || tdata.argnum >64) tdata.argnum = 10; flag |= NV_INTEGER; break; @@ -806,15 +806,9 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp nv_setattr(np,newflag&~NV_ASSIGN); else { - char *oldname=0; - int len=strlen(name); - if(tp->argnum==1 && newflag==NV_INTEGER && nv_isattr(np,NV_INTEGER)) - tp->argnum = 10; - if(np->nvfun && !nv_isarray(np) && name[len-1]=='.') + if(np->nvfun && !nv_isarray(np) && name[strlen(name)-1]=='.') newflag |= NV_NODISC; nv_newattr (np, newflag&~NV_ASSIGN,tp->argnum); - if(oldname) - np->nvname = oldname; } } if(tp->help && !nv_isattr(np,NV_MINIMAL|NV_EXPORT)) diff --git a/src/cmd/ksh93/tests/attributes.sh b/src/cmd/ksh93/tests/attributes.sh index 59b8acaf9..a448d171a 100755 --- a/src/cmd/ksh93/tests/attributes.sh +++ b/src/cmd/ksh93/tests/attributes.sh @@ -552,5 +552,13 @@ do unset foo done unset expect +unset base +for base in 0 1 65 +do unset x + typeset -i $base x + [[ $(typeset -p x) == 'typeset -i x' ]] || err_exit "typeset -i base limits failed to default to 10 with base: $base." +done +unset x base + # ====== exit $((Errors<125?Errors:125))