Skip to content

Commit

Permalink
14277 Improve shell lint checks
Browse files Browse the repository at this point in the history
Reviewed by: Robert Mustacchi <rm+illumos@fingolfin.org>
Approved by: Dan McDonald <danmcd@joyent.com>
  • Loading branch information
citrus-it committed Dec 6, 2021
1 parent ea3cb02 commit be548e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
5 changes: 2 additions & 3 deletions usr/src/contrib/ast/src/cmd/ksh93/data/lexstates.c
Expand Up @@ -393,14 +393,13 @@ const char e_lexsyntax2[] = "syntax error: `%s' %s";
const char e_lexsyntax3[] = "syntax error at line %d: duplicate label %s";
const char e_lexsyntax4[] = "syntax error at line %d: invalid reference list";
const char e_lexsyntax5[] = "syntax error at line %d: `<<%s' here-document not contained within command substitution";
const char e_lexwarnvar[] = "line %d: in '((%s))', using '$' is unnecessary, incurs a penalty and can introduce rounding errors.";
const char e_lexwarnvar[] = "line %d: in '((%s))', using '$' as in '$%.*s' is slower and can introduce rounding errors";
const char e_lexlabignore[] = "line %d: label %s ignored";
const char e_lexlabunknown[] = "line %d: %s unknown label";
const char e_lexobsolete1[] = "line %d: `...` obsolete, use $(...)";
const char e_lexobsolete2[] = "line %d: -a obsolete, use -e";
const char e_lexobsolete3[] = "line %d: '=' obsolete, use '=='";
const char e_lexobsolete4[] = "line %d: %s within [[...]] obsolete, use ((...))";
const char e_lexobsolete4b[] = "line %d: [[... %s ...]] obsolete, use ((... %s ...))";
const char e_lexobsolete4[] = "line %d: [[... %s ...]] obsolete, use ((... %s ...))";
const char e_lexobsolete5[] = "line %d: set %s obsolete";
const char e_lexobsolete6[] = "line %d: `{' instead of `in' is obsolete";
const char e_lexnonstandard[] = "line %d: `&>file' is nonstandard -- interpreted as `>file 2>&1' for profile input only";
Expand Down
39 changes: 19 additions & 20 deletions usr/src/contrib/ast/src/cmd/ksh93/sh/lex.c
Expand Up @@ -1462,36 +1462,35 @@ int sh_lex(Lex_t* lp)
default:
if(lp->lex.testop2)
{
#ifdef __ASTUpstream__
if(lp->lexd.warn && (c&TEST_ARITH))
errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete4,shp->inlineno,state);
#else
if(lp->lexd.warn && (c&TEST_ARITH)) {
char *alt = NULL;
char *alt;

if (strcmp(state, "-eq") == 0)
switch (c) {
case TEST_EQ:
alt = "==";
else if (strcmp(state, "-ne") == 0)
break;
case TEST_NE:
alt = "!=";
else if (strcmp(state, "-lt") == 0)
break;
case TEST_LT:
alt = "<";
else if (strcmp(state, "-gt") == 0)
break;
case TEST_GT:
alt = ">";
else if (strcmp(state, "-le") == 0)
break;
case TEST_LE:
alt = "<=";
else if (strcmp(state, "-ge") == 0)
break;
case TEST_GE:
alt = ">=";
if (alt != NULL) {
errormsg(SH_DICT, ERROR_warn(0),
e_lexobsolete4b,
shp->inlineno, state, alt);
} else {
errormsg(SH_DICT, ERROR_warn(0),
e_lexobsolete4,
shp->inlineno, state);
break;
default:
alt = "??";
}
errormsg(SH_DICT, ERROR_warn(0),
e_lexobsolete4,
shp->inlineno, state, alt);
}
#endif
if(c&TEST_PATTERN)
lp->lex.incase = 1;
else if(c==TEST_REP)
Expand Down
21 changes: 14 additions & 7 deletions usr/src/contrib/ast/src/cmd/ksh93/sh/parse.c
Expand Up @@ -251,32 +251,32 @@ static Shnode_t *makeparent(Lex_t *lp, int flag, Shnode_t *child)
return(par);
}

static int paramsub(const char *str)
static const char *paramsub(const char *str)
{
register int c,sub=0,lit=0;
while(c= *str++)
{
if(c=='$' && !lit)
{
if(*str=='(')
return(0);
return(NULL);
if(sub)
continue;
if(*str=='{')
str++;
if(!isdigit(*str) && strchr("?#@*!$ ",*str)==0)
return(1);
return(str);
}
else if(c=='`')
return(0);
return(NULL);
else if(c=='[' && !lit)
sub++;
else if(c==']' && !lit)
sub--;
else if(c=='\'')
lit = !lit;
}
return(0);
return(NULL);
}

static Shnode_t *getanode(Lex_t *lp, struct argnod *ap)
Expand All @@ -289,8 +289,15 @@ static Shnode_t *getanode(Lex_t *lp, struct argnod *ap)
t->ar.arcomp = sh_arithcomp(lp->sh,ap->argval);
else
{
if(sh_isoption(SH_NOEXEC) && (ap->argflag&ARG_MAC) && paramsub(ap->argval))
errormsg(SH_DICT,ERROR_warn(0),e_lexwarnvar,lp->sh->inlineno, ap->argval);
const char *p, *q;

if (sh_isoption(SH_NOEXEC) && (ap->argflag&ARG_MAC) &&
(p = paramsub(ap->argval)) != NULL) {
for (q = p; !isspace(*q) && *q != '\0'; q++)
;
errormsg(SH_DICT, ERROR_warn(0), e_lexwarnvar,
lp->sh->inlineno, ap->argval, q - p, p);
}
t->ar.arcomp = 0;
}
return(t);
Expand Down

0 comments on commit be548e8

Please sign in to comment.