diff -up pdksh-5.2.14/lex.c.aliases pdksh-5.2.14/lex.c --- pdksh-5.2.14/lex.c.aliases 2008-12-01 14:29:16.000000000 +0100 +++ pdksh-5.2.14/lex.c 2008-12-03 10:35:42.879559617 +0100 @@ -744,16 +744,25 @@ Done: if ((cf & ALIAS) && (p = tsearch(&aliases, ident, h)) && (p->flag & ISSET)) { - register Source *s; + register Source *s = source; - for (s = source; s->type == SALIAS; s = s->next) + while (s->flags & SF_HASALIAS) if (s->u.tblp == p) return LWORD; + else + s = s->next; + /* push alias expansion */ s = pushs(SALIAS, source->areap); s->start = s->str = p->val.s; s->u.tblp = p; + s->flags |= SF_HASALIAS; s->next = source; + if (source->type == SEOF) { + /* prevent infinite recursion at EOS */ + source->u.tblp = p; + source->flags |= SF_HASALIAS; + } source = s; afree(yylval.cp, ATEMP); goto Again; diff -up pdksh-5.2.14/lex.h.aliases pdksh-5.2.14/lex.h --- pdksh-5.2.14/lex.h.aliases 2008-12-03 10:37:42.558592408 +0100 +++ pdksh-5.2.14/lex.h 2008-12-03 10:41:02.040559514 +0100 @@ -14,7 +14,7 @@ struct source { union { char **strv; /* string [] */ struct shf *shf; /* shell file */ - struct tbl *tblp; /* alias (SALIAS) */ + struct tbl *tblp; /* alias (SF_HASALIAS) */ char *freeme; /* also for SREREAD */ } u; char ugbuf[2]; /* buffer for ungetsc() (SREREAD) and @@ -44,6 +44,7 @@ struct source { #define SF_ALIAS BIT(1) /* faking space at end of alias */ #define SF_ALIASEND BIT(2) /* faking space at end of alias */ #define SF_TTY BIT(3) /* type == SSTDIN & it is a tty */ +#define SF_HASALIAS BIT(5) /* u.tblp valid (SALIAS, SEOF) */ /* * states while lexing word