From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24916 invoked from network); 7 Apr 2000 02:19:16 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 7 Apr 2000 02:19:16 -0000 Received: (qmail 21659 invoked by alias); 7 Apr 2000 02:18:42 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10565 Received: (qmail 21646 invoked from network); 7 Apr 2000 02:18:41 -0000 Date: Thu, 6 Apr 2000 22:18:38 -0400 From: Clint Adams To: zsh-workers@sunsite.auc.dk Subject: PATCH: max-function-depth configure option Message-ID: <20000406221838.A8348@dman.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/1.1.2i This allows someone to hardcode the number of nested functions the shell will allow. The resulting behavior is hardly ideal, but I can't figure out what would be ideal. Exiting completely? Index: acconfig.h =================================================================== RCS file: /cvsroot/zsh/zsh/acconfig.h,v retrieving revision 1.1.1.14 diff -u -r1.1.1.14 acconfig.h --- acconfig.h 2000/02/28 04:36:33 1.1.1.14 +++ acconfig.h 2000/04/07 02:02:18 @@ -169,6 +169,9 @@ /* Define for Maildir support */ #undef MAILDIR_SUPPORT +/* Define for function depth limits */ +#undef MAX_FUNCTION_DEPTH + /* Define if you want locale features. By default this is defined. */ #undef CONFIG_LOCALE Index: configure.in =================================================================== RCS file: /cvsroot/zsh/zsh/configure.in,v retrieving revision 1.2 diff -u -r1.2 configure.in --- configure.in 2000/04/06 16:44:03 1.2 +++ configure.in 2000/04/07 02:02:18 @@ -271,6 +271,16 @@ AC_DEFINE(MAILDIR_SUPPORT) fi]) +dnl Do you want to set a maximum function depth? +undefine([max_function_depth])dnl +AC_ARG_ENABLE(max-function-depth, +[ --enable-max-function-depth=MAX Limit function depth to MAX], +[if test x$enableval = xyes; then + AC_DEFINE(MAX_FUNCTION_DEPTH, 4096) +else + AC_DEFINE_UNQUOTED(MAX_FUNCTION_DEPTH, $enableval) +fi]) + dnl ------------------ dnl CHECK THE COMPILER dnl ------------------ Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.2 diff -u -r1.2 exec.c --- Src/exec.c 2000/04/01 20:49:48 1.2 +++ Src/exec.c 2000/04/07 02:02:19 @@ -3251,6 +3251,9 @@ char saveopts[OPT_SIZE], *oldscriptname = NULL, *fname = dupstring(name); int obreaks; struct funcstack fstack; +#ifdef MAX_FUNCTION_DEPTH + static int funcdepth; +#endif pushheap(); @@ -3300,6 +3303,13 @@ argzero = ztrdup(argzero); } } +#ifdef MAX_FUNCTION_DEPTH + if(++funcdepth > MAX_FUNCTION_DEPTH) + { + zerr("maximum nested function level reached", NULL, 0); + return; + } +#endif fstack.name = dupstring(name); fstack.prev = funcstack; funcstack = &fstack; @@ -3323,6 +3333,9 @@ } runshfunc(prog, wrappers, fstack.name); funcstack = fstack.prev; +#ifdef MAX_FUNCTION_DEPTH + --funcdepth; +#endif if (retflag) { retflag = 0; breaks = obreaks;