From: Chris Lamb <la...@debian.org>

Bug-Debian: https://bugs.debian.org/579815
Signed-off-by: Chris Lamb <la...@debian.org>
Signed-off-by: Andrej Shadura <andrew.shad...@collabora.co.uk>
---
 src/eval.c | 8 +++++++-
 src/eval.h | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/eval.c b/src/eval.c
index 1aad31a..ee36c39 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;
@@ -903,7 +904,12 @@ raise:
                break;
 
        case CMDFUNCTION:
-               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 63e7d86..38dffbd 100644
--- a/src/eval.h
+++ b/src/eval.h
@@ -51,6 +51,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 */
 int evaltree(union node *, int);
-- 
2.20.1

Reply via email to