Patch by Thorsten Glaser for mksh <= 36, to solve some kind of "bug" resulting in command hang in mksh and also high cpu workload. For more information, please have a look to Red Hat Bugzilla ID #474115. And this patch is already in upstream version control system and will be included in upstream's next release. --- mksh-36/check.t 2008-10-24 23:36:05.000000000 +0200 +++ mksh-36/check.t.alias 2008-12-02 22:36:13.000000000 +0100 @@ -7,7 +7,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R36 2008/10/24 + @(#)MIRBSD KSH R36 2008/10/24 RedHat-1 description: Check version of shell. stdin: @@ -151,6 +151,20 @@ hi there --- +name: alias-9 +description: + Check that recursion is detected/avoided in aliases. +time-limit: 3 +stdin: + echo -n >tf + alias ls=ls + ls + echo $(ls) + exit 0 +expected-stdout: + tf + tf +--- name: arith-lazy-1 description: Check that only one side of ternary operator is evaluated --- mksh-36/lex.c 2008-10-10 23:31:05.000000000 +0200 +++ mksh-36/lex.c.alias 2008-12-02 22:33:53.000000000 +0100 @@ -904,16 +904,24 @@ /* prefer functions over aliases */ ktdelete(p); else { - Source *s; + 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; --- mksh-36/sh.h 2008-10-24 23:36:06.000000000 +0200 +++ mksh-36/sh.h.alias 2008-12-02 22:35:27.000000000 +0100 @@ -102,7 +102,7 @@ #ifdef EXTERN __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.245 2008/10/24 21:35:43 tg Exp $"); #endif -#define MKSH_VERSION "R36 2008/10/24" +#define MKSH_VERSION "R36 2008/10/24 RedHat-1" #ifndef MKSH_INCLUDES_ONLY @@ -1117,7 +1117,7 @@ union { const 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; int line; /* line number */ @@ -1148,6 +1148,7 @@ #define SF_ALIASEND BIT(2) /* faking space at end of alias */ #define SF_TTY BIT(3) /* type == SSTDIN & it is a tty */ #define SF_FIRST BIT(4) /* initial state (to ignore UTF-8 BOM) */ +#define SF_HASALIAS BIT(5) /* u.tblp valid (SALIAS, SEOF) */ typedef union { int i;