diff -Naur php-5.2.6.orig/main/main.c php-5.2.6.back/main/main.c --- php-5.2.6.orig/main/main.c 2008-03-05 15:58:08.000000000 -0500 +++ php-5.2.6.back/main/main.c 2008-09-01 22:19:24.000000000 -0400 @@ -972,6 +985,7 @@ case E_PARSE: case E_COMPILE_ERROR: case E_USER_ERROR: + EG(stack_nbr) = 0; EG(exit_status) = 255; if (module_initialized) { if (!PG(display_errors) && @@ -1930,6 +1989,7 @@ #endif int retval = 0; + EG(stack_nbr) = 0; EG(exit_status) = 0; if (php_handle_special_queries(TSRMLS_C)) { zend_file_handle_dtor(primary_file); @@ -2027,6 +2087,7 @@ { char *old_cwd; + EG(stack_nbr) = 0; EG(exit_status) = 0; #define OLD_CWD_SIZE 4096 old_cwd = do_alloca(OLD_CWD_SIZE); diff -Naur php-5.2.6.orig/Zend/zend.c php-5.2.6.back/Zend/zend.c --- php-5.2.6.orig/Zend/zend.c 2007-12-31 02:20:02.000000000 -0500 +++ php-5.2.6.back/Zend/zend.c 2008-09-01 22:57:07.000000000 -0400 @@ -78,6 +78,8 @@ ZEND_INI_BEGIN() ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting) STD_ZEND_INI_BOOLEAN("zend.ze1_compatibility_mode", "0", ZEND_INI_ALL, OnUpdateBool, ze1_compatibility_mode, zend_executor_globals, executor_globals) + STD_ZEND_INI_ENTRY("e3bsecurity.call_stack_size", "20000", ZEND_INI_SYSTEM, OnUpdateLong, e3b_stack_size,zend_executor_globals, executor_globals) + //E3b: I guess it we should allow to change this setting in .htaccess too... #ifdef ZEND_MULTIBYTE STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals) #endif diff -Naur php-5.2.6.orig/Zend/zend_globals.h php-5.2.6.back/Zend/zend_globals.h --- php-5.2.6.orig/Zend/zend_globals.h 2007-12-31 02:20:02.000000000 -0500 +++ php-5.2.6.back/Zend/zend_globals.h 2008-09-01 22:56:57.000000000 -0400 @@ -179,6 +179,8 @@ int error_reporting; int orig_error_reporting; int exit_status; + int stack_nbr; + long e3b_stack_size; zend_op_array *active_op_array; diff -Naur php-5.2.6.orig/Zend/zend_vm_execute.h php-5.2.6.back/Zend/zend_vm_execute.h --- php-5.2.6.orig/Zend/zend_vm_execute.h 2008-03-04 06:46:09.000000000 -0500 +++ php-5.2.6.back/Zend/zend_vm_execute.h 2008-09-01 23:24:00.000000000 -0400 @@ -124,6 +124,10 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS) { + EG(stack_nbr)++; + if (EG(e3b_stack_size) != 0 && EG(stack_nbr)>=EG(e3b_stack_size)) { zend_error_noreturn(E_ERROR, "E3b Security: Stack Overflow: Deep Recursion detected %d callbacks.", EG(stack_nbr));} + //printf("Stack: %d\n",EG(stack_nbr)); + zend_op *opline = EX(opline); zval **original_return_value; zend_class_entry *current_scope = NULL; @@ -312,7 +316,7 @@ zval_ptr_dtor(&EX_T(opline->result.u.var).var.ptr); } } - + EG(stack_nbr)--; ZEND_VM_NEXT_OPCODE(); }