Index: trunk/src/mregex.c
===================================================================
--- trunk/src/mregex.c	(Revision 2364)
+++ trunk/src/mregex.c	(Arbeitskopie)
@@ -408,6 +408,21 @@
             errorf("pcre: %s\n", pErrmsg);
         return 0;
     }
+    /* We have to ensure to have an initialized pHints structure for
+       setting the recursion limit later on */
+    if (pHints == NULL) 
+    {
+        pcre_malloc_err = "allocating memory for pHints section in regexp";
+        pHints = (pcre_extra *)pcre_xalloc(sizeof(pcre_extra));
+        if (pHints == NULL) 
+        {
+            if (from_ed)
+                add_message("pcre: Could not allocate memory for pHints\n");
+            else
+                errorf("pcre: Could not allocate memory for pHints\n");
+            return 0;
+        }
+    }
 
     {
        int rc;
@@ -672,18 +687,28 @@
         if (prog->opt & RE_NOTEMPTY) pcre_opt |= PCRE_NOTEMPTY;
 
         pHints = prog->pHints;
-        if (pHints && max_eval_cost)
-        {
-            pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
-            if (max_eval_cost > eval_cost + 1)
-                pHints->match_limit = max_eval_cost - eval_cost - 1;
-            else
-                pHints->match_limit = 1;
-        }
-        else if (pHints)
-        {
-            pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
-        }
+        /* If PCRE_RECURSION_LIMIT is defined we set a limit for match. If
+         * PCRE_EXTRA_MATCH_LIMIT_RECURSION is defined, we have a new libpcre,
+         * which supports limiting the recursions. Otherwise we have to limit
+         * the no of calls to match().
+         * TODO: Instead of the conditional compilation we should update the
+         * TODO::built-in pcre package.
+         */
+#ifdef PCRE_RECURSION_LIMIT
+#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
+        pHints->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
+        pHints->match_limit_recursion = PCRE_RECURSION_LIMIT;
+#else
+        pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
+        pHints->match_limit = PCRE_RECURSION_LIMIT;
+#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
+#else  /* PCRE_RECURSION_LIMIT */
+#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
+        pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION
+#else
+        pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
+#endif  /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
+#endif  /* PCRE_RECURSION_LIMIT */
 
         rc = pcre_exec( prog->pProg, pHints
                       , get_txt(string), mstrsize(string), start, pcre_opt
@@ -735,18 +760,28 @@
         if (prog->opt & RE_NOTEMPTY) pcre_opt |= PCRE_NOTEMPTY;
 
         pHints = prog->pHints;
-        if (pHints && max_eval_cost)
-        {
-            pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
-            if (max_eval_cost > eval_cost + 1)
-                pHints->match_limit = max_eval_cost - eval_cost - 1;
-            else
-                pHints->match_limit = 1;
-        }
-        else if (pHints)
-        {
-            pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
-        }
+        /* If PCRE_RECURSION_LIMIT is defined we set a limit for match. If
+         * PCRE_EXTRA_MATCH_LIMIT_RECURSION is defined, we have a new libpcre,
+         * which supports limiting the recursions. Otherwise we have to limit
+         * the no of calls to match().
+         * TODO: Instead of the conditional compilation we should update the
+         * TODO::built-in pcre package.
+         */
+#ifdef PCRE_RECURSION_LIMIT
+#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
+        pHints->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
+        pHints->match_limit_recursion = PCRE_RECURSION_LIMIT;
+#else
+        pHints->flags |= PCRE_EXTRA_MATCH_LIMIT;
+        pHints->match_limit = PCRE_RECURSION_LIMIT;
+#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
+#else  /* PCRE_RECURSION_LIMIT */
+#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
+        pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION
+#else
+        pHints->flags &= ~PCRE_EXTRA_MATCH_LIMIT;
+#endif  /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */
+#endif  /* PCRE_RECURSION_LIMIT */
 
         rc = pcre_exec( prog->pProg, pHints
                       , start, strlen(start), string - start, pcre_opt
Index: trunk/src/autoconf/configure.in
===================================================================
--- trunk/src/autoconf/configure.in	(Revision 2364)
+++ trunk/src/autoconf/configure.in	(Arbeitskopie)
@@ -217,6 +217,7 @@
 AC_MY_ARG_WITH(min-small-malloced,0,,)
 AC_MY_ARG_WITH(max-malloced,0x4000000,,)
 AC_MY_ARG_WITH(total-trace-length,0x1000,,)
+AC_MY_ARG_WITH(pcre-recursion-limit,7000,,[maximum number of recursions in PCRE package])
 AC_MY_ARG_WITH(wizlist-file,WIZLIST,,[name of the wizlist file])
 
 AC_ARG_WITH(setting,[  --with-setting=SETTING  include a predefined setting],[
@@ -444,6 +445,7 @@
 AC_INT_VAL_FROM_WITH(min_small_malloced)
 AC_INT_VAL_FROM_WITH(max_malloced)
 AC_INT_VAL_FROM_WITH(total_trace_length)
+AC_INT_VAL_FROM_WITH(pcre_recursion_limit)
 
 if test "x$cdef_access_control" = "x#undef"; then
   cdef_access_log="#undef"
@@ -2739,6 +2741,7 @@
 AC_SUBST(val_max_malloced)
 AC_SUBST(val_total_trace_length)
 AC_SUBST(val_wizlist_file)
+AC_SUBST(val_pcre_recursion_limit)
 
 dnl finally: some remaining stuff
 dnl
Index: trunk/src/config.h.in
===================================================================
--- trunk/src/config.h.in	(Revision 2364)
+++ trunk/src/config.h.in	(Arbeitskopie)
@@ -434,6 +434,16 @@
 #define ALLOWED_ED_CMDS           @val_allowed_ed_cmds@
 /* TODO: ALLOWED_ED_CMDS: make this a runtime option */
 
+/* Limit the amount of recursion in the PCRE code. Setting it to low will
+ * prevent certain regexps to be executed properly, setting it too high can
+ * cause that regexps to crash the driver. Set it according to the
+ * available maximum stack size for the driver process. (Rule of thumb:
+ * The memory used for a recursion on the stack seems to be within 466 and
+ * 1008 bytes. If you have 8M of stack size, choose 7000 - 8000.)
+ * Defaults to 7000
+ */                                                                                       
+#define PCRE_RECURSION_LIMIT    @val_pcre_recursion_limit@                                
+			
 
 /* --- Compiler --- */
 
Index: trunk/src/pkg-pcre.h
===================================================================
--- trunk/src/pkg-pcre.h	(Revision 2364)
+++ trunk/src/pkg-pcre.h	(Arbeitskopie)
@@ -22,6 +22,10 @@
 
 /* Error code to be returned if too many backtracks are detected.
  */
+#ifdef PCRE_ERROR_RECURSIONLIMIT
+#define RE_ERROR_BACKTRACK PCRE_ERROR_RECURSIONLIMIT
+#else
 #define RE_ERROR_BACKTRACK PCRE_ERROR_MATCHLIMIT
+#endif
 
 #endif /* PKG_PCRE_H_ */
