zsh-workers
 help / color / mirror / code / Atom feed
From: Clint Adams <schizo@debian.org>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: max-function-depth configure option
Date: Thu, 6 Apr 2000 22:18:38 -0400	[thread overview]
Message-ID: <20000406221838.A8348@dman.com> (raw)

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;


                 reply	other threads:[~2000-04-07  2:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20000406221838.A8348@dman.com \
    --to=schizo@debian.org \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).