tags 579815 + patch
thanks

Hi,

> dash: stack overflow from infinite recursion in script

Dumb patch:

  diff --git a/src/eval.c b/src/eval.c
  index c7358a6..fc456ee 100644
  --- a/src/eval.c
  +++ b/src/eval.c
  @@ -69,6 +69,7 @@ int evalskip;                       /* set if we are 
skipping commands */
   STATIC int skipcount;                /* number of levels to skip */
   MKINIT int loopnest;         /* current loop nesting level */
   static int funcline;         /* starting line number of current function, or 
0 if not in a function */
  +static int evalcount;        /* number of nested evalfun calls */
   
   
   char *commandname;
  @@ -868,7 +869,12 @@ raise:
   
        case CMDFUNCTION:
                poplocalvars(1);
  -             if (evalfun(cmdentry.u.func, argc, argv, flags))
  +             if (evalcount++ >= MAX_RECURSION)
  +                     sh_error("Maximum function recursion depth (%d) 
reached",
  +                              MAX_RECURSION);
  +             int i = evalfun(cmdentry.u.func, argc, argv, flags);
  +             evalcount--;
  +             if (i)
                        goto raise;
                break;
        }
  diff --git a/src/eval.h b/src/eval.h
  index dc8acd2..22b950e 100644
  --- a/src/eval.h
  +++ b/src/eval.h
  @@ -50,6 +50,8 @@ struct backcmd {            /* result of evalbackcmd */
   #define EV_EXIT 01           /* exit after evaluating tree */
   #define EV_TESTED 02         /* exit status is checked; ignore -e flag */
   
  +#define MAX_RECURSION 1000   /* maximum recursion level */
  +
   int evalstring(char *, int);
   union node;  /* BLETCH for ansi C */
   void evaltree(union node *, int);



Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      [email protected] / chris-lamb.co.uk
       `-

Reply via email to