PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - main - main.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 720 930 77.4 %
Date: 2015-05-21 Functions: 51 61 83.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2015 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Rasmus Lerdorf <rasmus@lerdorf.on.ca>                       |
      17             :    |          Zeev Suraski <zeev@zend.com>                                |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : /* {{{ includes
      24             :  */
      25             : 
      26             : #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
      27             : 
      28             : #include "php.h"
      29             : #include <stdio.h>
      30             : #include <fcntl.h>
      31             : #ifdef PHP_WIN32
      32             : #include "win32/time.h"
      33             : #include "win32/signal.h"
      34             : #include "win32/php_win32_globals.h"
      35             : #include "win32/winutil.h"
      36             : #include <process.h>
      37             : #elif defined(NETWARE)
      38             : #include <sys/timeval.h>
      39             : #ifdef USE_WINSOCK
      40             : #include <novsock2.h>
      41             : #endif
      42             : #endif
      43             : #if HAVE_SYS_TIME_H
      44             : #include <sys/time.h>
      45             : #endif
      46             : #if HAVE_UNISTD_H
      47             : #include <unistd.h>
      48             : #endif
      49             : #if HAVE_SIGNAL_H
      50             : #include <signal.h>
      51             : #endif
      52             : #if HAVE_SETLOCALE
      53             : #include <locale.h>
      54             : #endif
      55             : #include "zend.h"
      56             : #include "zend_types.h"
      57             : #include "zend_extensions.h"
      58             : #include "php_ini.h"
      59             : #include "php_globals.h"
      60             : #include "php_main.h"
      61             : #include "fopen_wrappers.h"
      62             : #include "ext/standard/php_standard.h"
      63             : #include "ext/standard/php_string.h"
      64             : #include "ext/date/php_date.h"
      65             : #include "php_variables.h"
      66             : #include "ext/standard/credits.h"
      67             : #ifdef PHP_WIN32
      68             : #include <io.h>
      69             : #include "win32/php_registry.h"
      70             : #include "ext/standard/flock_compat.h"
      71             : #endif
      72             : #include "php_syslog.h"
      73             : #include "Zend/zend_exceptions.h"
      74             : 
      75             : #if PHP_SIGCHILD
      76             : #include <sys/types.h>
      77             : #include <sys/wait.h>
      78             : #endif
      79             : 
      80             : #include "zend_compile.h"
      81             : #include "zend_execute.h"
      82             : #include "zend_highlight.h"
      83             : #include "zend_extensions.h"
      84             : #include "zend_ini.h"
      85             : #include "zend_dtrace.h"
      86             : 
      87             : #include "php_content_types.h"
      88             : #include "php_ticks.h"
      89             : #include "php_streams.h"
      90             : #include "php_open_temporary_file.h"
      91             : 
      92             : #include "SAPI.h"
      93             : #include "rfc1867.h"
      94             : 
      95             : #if HAVE_MMAP || defined(PHP_WIN32)
      96             : # if HAVE_UNISTD_H
      97             : #  include <unistd.h>
      98             : #  if defined(_SC_PAGESIZE)
      99             : #    define REAL_PAGE_SIZE sysconf(_SC_PAGESIZE);
     100             : #  elif defined(_SC_PAGE_SIZE)
     101             : #    define REAL_PAGE_SIZE sysconf(_SC_PAGE_SIZE);
     102             : #  endif
     103             : # endif
     104             : # if HAVE_SYS_MMAN_H
     105             : #  include <sys/mman.h>
     106             : # endif
     107             : # ifndef REAL_PAGE_SIZE
     108             : #  ifdef PAGE_SIZE
     109             : #   define REAL_PAGE_SIZE PAGE_SIZE
     110             : #  else
     111             : #   define REAL_PAGE_SIZE 4096
     112             : #  endif
     113             : # endif
     114             : #endif
     115             : /* }}} */
     116             : 
     117             : #ifndef S_ISREG
     118             : #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
     119             : #endif
     120             : 
     121             : PHPAPI int (*php_register_internal_extensions_func)(void) = php_register_internal_extensions;
     122             : 
     123             : #ifndef ZTS
     124             : php_core_globals core_globals;
     125             : #else
     126             : PHPAPI int core_globals_id;
     127             : #endif
     128             : 
     129             : #define SAFE_FILENAME(f) ((f)?(f):"-")
     130             : 
     131             : /* {{{ PHP_INI_MH
     132             :  */
     133       21499 : static PHP_INI_MH(OnSetPrecision)
     134             : {
     135             :         zend_long i;
     136             : 
     137       21499 :         ZEND_ATOL(i, new_value->val);
     138       21499 :         if (i >= 0) {
     139       21499 :                 EG(precision) = i;
     140       21499 :                 return SUCCESS;
     141             :         } else {
     142           0 :                 return FAILURE;
     143             :         }
     144             : }
     145             : /* }}} */
     146             : 
     147             : /* {{{ PHP_INI_MH
     148             :  */
     149       20922 : static PHP_INI_MH(OnChangeMemoryLimit)
     150             : {
     151       20922 :         if (new_value) {
     152       20922 :                 PG(memory_limit) = zend_atol(new_value->val, (int)new_value->len);
     153             :         } else {
     154           0 :                 PG(memory_limit) = 1<<30;         /* effectively, no limit */
     155             :         }
     156       20922 :         return zend_set_memory_limit(PG(memory_limit));
     157             : }
     158             : /* }}} */
     159             : 
     160             : 
     161             : /* {{{ php_disable_functions
     162             :  */
     163       20916 : static void php_disable_functions(void)
     164             : {
     165       20916 :         char *s = NULL, *e;
     166             : 
     167       20916 :         if (!*(INI_STR("disable_functions"))) {
     168       20912 :                 return;
     169             :         }
     170             : 
     171           4 :         e = PG(disable_functions) = strdup(INI_STR("disable_functions"));
     172           4 :         if (e == NULL) {
     173           0 :                 return;
     174             :         }
     175          77 :         while (*e) {
     176          69 :                 switch (*e) {
     177             :                         case ' ':
     178             :                         case ',':
     179           4 :                                 if (s) {
     180           4 :                                         *e = '\0';
     181           4 :                                         zend_disable_function(s, e-s);
     182           4 :                                         s = NULL;
     183             :                                 }
     184           4 :                                 break;
     185             :                         default:
     186          65 :                                 if (!s) {
     187           8 :                                         s = e;
     188             :                                 }
     189             :                                 break;
     190             :                 }
     191          69 :                 e++;
     192             :         }
     193           4 :         if (s) {
     194           4 :                 zend_disable_function(s, e-s);
     195             :         }
     196             : }
     197             : /* }}} */
     198             : 
     199             : /* {{{ php_disable_classes
     200             :  */
     201       20916 : static void php_disable_classes(void)
     202             : {
     203       20916 :         char *s = NULL, *e;
     204             : 
     205       20916 :         if (!*(INI_STR("disable_classes"))) {
     206       20915 :                 return;
     207             :         }
     208             : 
     209           1 :         e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
     210             : 
     211          10 :         while (*e) {
     212           8 :                 switch (*e) {
     213             :                         case ' ':
     214             :                         case ',':
     215           0 :                                 if (s) {
     216           0 :                                         *e = '\0';
     217           0 :                                         zend_disable_class(s, e-s);
     218           0 :                                         s = NULL;
     219             :                                 }
     220           0 :                                 break;
     221             :                         default:
     222           8 :                                 if (!s) {
     223           1 :                                         s = e;
     224             :                                 }
     225             :                                 break;
     226             :                 }
     227           8 :                 e++;
     228             :         }
     229           1 :         if (s) {
     230           1 :                 zend_disable_class(s, e-s);
     231             :         }
     232             : }
     233             : /* }}} */
     234             : 
     235             : /* {{{ php_binary_init
     236             :  */
     237       20916 : static void php_binary_init(void)
     238             : {
     239             :         char *binary_location;
     240             : #ifdef PHP_WIN32
     241             :         binary_location = (char *)malloc(MAXPATHLEN);
     242             :         if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
     243             :                 free(binary_location);
     244             :                 PG(php_binary) = NULL;
     245             :         }
     246             : #else
     247       20916 :         if (sapi_module.executable_location) {
     248       20916 :                 binary_location = (char *)malloc(MAXPATHLEN);
     249       20916 :                 if (!strchr(sapi_module.executable_location, '/')) {
     250             :                         char *envpath, *path;
     251           0 :                         int found = 0;
     252             : 
     253           0 :                         if ((envpath = getenv("PATH")) != NULL) {
     254             :                                 char *search_dir, search_path[MAXPATHLEN];
     255           0 :                                 char *last = NULL;
     256             :                                 zend_stat_t s;
     257             : 
     258           0 :                                 path = estrdup(envpath);
     259           0 :                                 search_dir = php_strtok_r(path, ":", &last);
     260             : 
     261           0 :                                 while (search_dir) {
     262           0 :                                         snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
     263           0 :                                         if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK) && VCWD_STAT(binary_location, &s) == 0 && S_ISREG(s.st_mode)) {
     264           0 :                                                 found = 1;
     265           0 :                                                 break;
     266             :                                         }
     267           0 :                                         search_dir = php_strtok_r(NULL, ":", &last);
     268             :                                 }
     269           0 :                                 efree(path);
     270             :                         }
     271           0 :                         if (!found) {
     272           0 :                                 free(binary_location);
     273           0 :                                 binary_location = NULL;
     274             :                         }
     275       20916 :                 } else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
     276           0 :                         free(binary_location);
     277           0 :                         binary_location = NULL;
     278             :                 }
     279             :         } else {
     280           0 :                 binary_location = NULL;
     281             :         }
     282             : #endif
     283       20916 :         PG(php_binary) = binary_location;
     284       20916 : }
     285             : /* }}} */
     286             : 
     287             : /* {{{ PHP_INI_MH
     288             :  */
     289       20971 : static PHP_INI_MH(OnUpdateTimeout)
     290             : {
     291       20971 :         if (stage==PHP_INI_STAGE_STARTUP) {
     292             :                 /* Don't set a timeout on startup, only per-request */
     293       20916 :                 ZEND_ATOL(EG(timeout_seconds), new_value->val);
     294       20916 :                 return SUCCESS;
     295             :         }
     296          55 :         zend_unset_timeout();
     297          55 :         ZEND_ATOL(EG(timeout_seconds), new_value->val);
     298          55 :         zend_set_timeout(EG(timeout_seconds), 0);
     299          55 :         return SUCCESS;
     300             : }
     301             : /* }}} */
     302             : 
     303             : /* {{{ php_get_display_errors_mode() helper function
     304             :  */
     305       21216 : static int php_get_display_errors_mode(char *value, int value_length)
     306             : {
     307             :         int mode;
     308             : 
     309       21216 :         if (!value) {
     310           0 :                 return PHP_DISPLAY_ERRORS_STDOUT;
     311             :         }
     312             : 
     313       21217 :         if (value_length == 2 && !strcasecmp("on", value)) {
     314           1 :                 mode = PHP_DISPLAY_ERRORS_STDOUT;
     315       21215 :         } else if (value_length == 3 && !strcasecmp("yes", value)) {
     316           0 :                 mode = PHP_DISPLAY_ERRORS_STDOUT;
     317       21215 :         } else if (value_length == 4 && !strcasecmp("true", value)) {
     318           0 :                 mode = PHP_DISPLAY_ERRORS_STDOUT;
     319       21217 :         } else if (value_length == 6 && !strcasecmp(value, "stderr")) {
     320           2 :                 mode = PHP_DISPLAY_ERRORS_STDERR;
     321       21214 :         } else if (value_length == 6 && !strcasecmp(value, "stdout")) {
     322           1 :                 mode = PHP_DISPLAY_ERRORS_STDOUT;
     323             :         } else {
     324       21212 :                 ZEND_ATOL(mode, value);
     325       21212 :                 if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
     326           0 :                         mode = PHP_DISPLAY_ERRORS_STDOUT;
     327             :                 }
     328             :         }
     329             : 
     330       21216 :         return mode;
     331             : }
     332             : /* }}} */
     333             : 
     334             : /* {{{ PHP_INI_MH
     335             :  */
     336       20932 : static PHP_INI_MH(OnUpdateDisplayErrors)
     337             : {
     338       20932 :         PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value->val, (int)new_value->len);
     339             : 
     340       20932 :         return SUCCESS;
     341             : }
     342             : /* }}} */
     343             : 
     344             : /* {{{ PHP_INI_DISP
     345             :  */
     346         284 : static PHP_INI_DISP(display_errors_mode)
     347             : {
     348             :         int mode, tmp_value_length, cgi_or_cli;
     349             :         char *tmp_value;
     350             : 
     351         284 :         if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
     352           0 :                 tmp_value = (ini_entry->orig_value ? ini_entry->orig_value->val : NULL );
     353           0 :                 tmp_value_length = (int)(ini_entry->orig_value? ini_entry->orig_value->len : 0);
     354         284 :         } else if (ini_entry->value) {
     355         284 :                 tmp_value = ini_entry->value->val;
     356         284 :                 tmp_value_length = (int)ini_entry->value->len;
     357             :         } else {
     358           0 :                 tmp_value = NULL;
     359           0 :                 tmp_value_length = 0;
     360             :         }
     361             : 
     362         284 :         mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
     363             : 
     364             :         /* Display 'On' for other SAPIs instead of STDOUT or STDERR */
     365         284 :         cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi"));
     366             : 
     367         284 :         switch (mode) {
     368             :                 case PHP_DISPLAY_ERRORS_STDERR:
     369           0 :                         if (cgi_or_cli ) {
     370           0 :                                 PUTS("STDERR");
     371             :                         } else {
     372           0 :                                 PUTS("On");
     373             :                         }
     374           0 :                         break;
     375             : 
     376             :                 case PHP_DISPLAY_ERRORS_STDOUT:
     377         252 :                         if (cgi_or_cli ) {
     378         250 :                                 PUTS("STDOUT");
     379             :                         } else {
     380           2 :                                 PUTS("On");
     381             :                         }
     382         252 :                         break;
     383             : 
     384             :                 default:
     385          32 :                         PUTS("Off");
     386             :                         break;
     387             :         }
     388         284 : }
     389             : /* }}} */
     390             : 
     391             : /* {{{ PHP_INI_MH
     392             :  */
     393       20924 : static PHP_INI_MH(OnUpdateInternalEncoding)
     394             : {
     395       20924 :         if (new_value) {
     396          14 :                 OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
     397             :         }
     398       20924 :         return SUCCESS;
     399             : }
     400             : /* }}} */
     401             : 
     402             : /* {{{ PHP_INI_MH
     403             :  */
     404       20924 : static PHP_INI_MH(OnUpdateInputEncoding)
     405             : {
     406       20924 :         if (new_value) {
     407          14 :                 OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
     408             :         }
     409       20924 :         return SUCCESS;
     410             : }
     411             : /* }}} */
     412             : 
     413             : /* {{{ PHP_INI_MH
     414             :  */
     415       20924 : static PHP_INI_MH(OnUpdateOutputEncoding)
     416             : {
     417       20924 :         if (new_value) {
     418          14 :                 OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
     419             :         }
     420       20924 :         return SUCCESS;
     421             : }
     422             : /* }}} */
     423             : 
     424             : /* {{{ PHP_INI_MH
     425             :  */
     426       20921 : static PHP_INI_MH(OnUpdateErrorLog)
     427             : {
     428             :         /* Only do the safemode/open_basedir check at runtime */
     429       20921 :         if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value->val, "syslog")) {
     430           3 :                 if (PG(open_basedir) && php_check_open_basedir(new_value->val)) {
     431           0 :                         return FAILURE;
     432             :                 }
     433             :         }
     434       20921 :         OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
     435       20921 :         return SUCCESS;
     436             : }
     437             : /* }}} */
     438             : 
     439             : /* {{{ PHP_INI_MH
     440             :  */
     441       20916 : static PHP_INI_MH(OnUpdateMailLog)
     442             : {
     443             :         /* Only do the safemode/open_basedir check at runtime */
     444       20916 :         if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {
     445           0 :                 if (PG(open_basedir) && php_check_open_basedir(new_value->val)) {
     446           0 :                         return FAILURE;
     447             :                 }
     448             :         }
     449       20916 :         OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
     450       20916 :         return SUCCESS;
     451             : }
     452             : /* }}} */
     453             : 
     454             : /* {{{ PHP_INI_MH
     455             :  */
     456       20916 : static PHP_INI_MH(OnChangeMailForceExtra)
     457             : {
     458             :         /* Don't allow changing it in htaccess */
     459       20916 :         if (stage == PHP_INI_STAGE_HTACCESS) {
     460           0 :                         return FAILURE;
     461             :         }
     462       20916 :         return SUCCESS;
     463             : }
     464             : /* }}} */
     465             : 
     466             : /* defined in browscap.c */
     467             : PHP_INI_MH(OnChangeBrowscap);
     468             : 
     469             : 
     470             : /* Need to be read from the environment (?):
     471             :  * PHP_AUTO_PREPEND_FILE
     472             :  * PHP_AUTO_APPEND_FILE
     473             :  * PHP_DOCUMENT_ROOT
     474             :  * PHP_USER_DIR
     475             :  * PHP_INCLUDE_PATH
     476             :  */
     477             : 
     478             :  /* Windows and Netware use the internal mail */
     479             : #if defined(PHP_WIN32) || defined(NETWARE)
     480             : # define DEFAULT_SENDMAIL_PATH NULL
     481             : #elif defined(PHP_PROG_SENDMAIL)
     482             : # define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
     483             : #else
     484             : # define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"
     485             : #endif
     486             : 
     487             : /* {{{ PHP_INI
     488             :  */
     489             : PHP_INI_BEGIN()
     490             :         PHP_INI_ENTRY_EX("highlight.comment",         HL_COMMENT_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
     491             :         PHP_INI_ENTRY_EX("highlight.default",         HL_DEFAULT_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
     492             :         PHP_INI_ENTRY_EX("highlight.html",                    HL_HTML_COLOR,          PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
     493             :         PHP_INI_ENTRY_EX("highlight.keyword",         HL_KEYWORD_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
     494             :         PHP_INI_ENTRY_EX("highlight.string",          HL_STRING_COLOR,        PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
     495             : 
     496             :         STD_PHP_INI_ENTRY_EX("display_errors",                "1",          PHP_INI_ALL,            OnUpdateDisplayErrors,  display_errors,                 php_core_globals,       core_globals, display_errors_mode)
     497             :         STD_PHP_INI_BOOLEAN("display_startup_errors", "0",  PHP_INI_ALL,            OnUpdateBool,                   display_startup_errors, php_core_globals,       core_globals)
     498             :         STD_PHP_INI_BOOLEAN("enable_dl",                      "1",          PHP_INI_SYSTEM,         OnUpdateBool,                   enable_dl,                              php_core_globals,       core_globals)
     499             :         STD_PHP_INI_BOOLEAN("expose_php",                     "1",          PHP_INI_SYSTEM,         OnUpdateBool,                   expose_php,                             php_core_globals,       core_globals)
     500             :         STD_PHP_INI_ENTRY("docref_root",                      "",           PHP_INI_ALL,            OnUpdateString,                 docref_root,                    php_core_globals,       core_globals)
     501             :         STD_PHP_INI_ENTRY("docref_ext",                               "",                   PHP_INI_ALL,            OnUpdateString,                 docref_ext,                             php_core_globals,       core_globals)
     502             :         STD_PHP_INI_BOOLEAN("html_errors",                    "1",          PHP_INI_ALL,            OnUpdateBool,                   html_errors,                    php_core_globals,       core_globals)
     503             :         STD_PHP_INI_BOOLEAN("xmlrpc_errors",          "0",          PHP_INI_SYSTEM,         OnUpdateBool,                   xmlrpc_errors,                  php_core_globals,       core_globals)
     504             :         STD_PHP_INI_ENTRY("xmlrpc_error_number",      "0",          PHP_INI_ALL,            OnUpdateLong,                   xmlrpc_error_number,    php_core_globals,       core_globals)
     505             :         STD_PHP_INI_ENTRY("max_input_time",                   "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateLong,                   max_input_time, php_core_globals,       core_globals)
     506             :         STD_PHP_INI_BOOLEAN("ignore_user_abort",      "0",          PHP_INI_ALL,            OnUpdateBool,                   ignore_user_abort,              php_core_globals,       core_globals)
     507             :         STD_PHP_INI_BOOLEAN("implicit_flush",         "0",          PHP_INI_ALL,            OnUpdateBool,                   implicit_flush,                 php_core_globals,       core_globals)
     508             :         STD_PHP_INI_BOOLEAN("log_errors",                     "0",          PHP_INI_ALL,            OnUpdateBool,                   log_errors,                             php_core_globals,       core_globals)
     509             :         STD_PHP_INI_ENTRY("log_errors_max_len",        "1024",              PHP_INI_ALL,            OnUpdateLong,                   log_errors_max_len,             php_core_globals,       core_globals)
     510             :         STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0",  PHP_INI_ALL,            OnUpdateBool,                   ignore_repeated_errors, php_core_globals,       core_globals)
     511             :         STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0",  PHP_INI_ALL,            OnUpdateBool,                   ignore_repeated_source, php_core_globals,       core_globals)
     512             :         STD_PHP_INI_BOOLEAN("report_memleaks",                "1",          PHP_INI_ALL,            OnUpdateBool,                   report_memleaks,                php_core_globals,       core_globals)
     513             :         STD_PHP_INI_BOOLEAN("report_zend_debug",      "1",          PHP_INI_ALL,            OnUpdateBool,                   report_zend_debug,              php_core_globals,       core_globals)
     514             :         STD_PHP_INI_ENTRY("output_buffering",         "0",          PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateLong,   output_buffering,               php_core_globals,       core_globals)
     515             :         STD_PHP_INI_ENTRY("output_handler",                   NULL,           PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateString, output_handler,         php_core_globals,       core_globals)
     516             :         STD_PHP_INI_BOOLEAN("register_argc_argv",     "1",          PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   register_argc_argv,             php_core_globals,       core_globals)
     517             :         STD_PHP_INI_BOOLEAN("auto_globals_jit",               "1",          PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   auto_globals_jit,       php_core_globals,       core_globals)
     518             :         STD_PHP_INI_BOOLEAN("short_open_tag", DEFAULT_SHORT_OPEN_TAG, PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,                   short_tags,                             zend_compiler_globals,  compiler_globals)
     519             :         STD_PHP_INI_BOOLEAN("sql.safe_mode",          "0",          PHP_INI_SYSTEM,         OnUpdateBool,                   sql_safe_mode,                  php_core_globals,       core_globals)
     520             :         STD_PHP_INI_BOOLEAN("track_errors",                   "0",          PHP_INI_ALL,            OnUpdateBool,                   track_errors,                   php_core_globals,       core_globals)
     521             : 
     522             :         STD_PHP_INI_ENTRY("unserialize_callback_func",        NULL,   PHP_INI_ALL,            OnUpdateString,                 unserialize_callback_func,      php_core_globals,       core_globals)
     523             :         STD_PHP_INI_ENTRY("serialize_precision",      "17", PHP_INI_ALL,            OnUpdateLongGEZero,                     serialize_precision,    php_core_globals,       core_globals)
     524             :         STD_PHP_INI_ENTRY("arg_separator.output",     "&",              PHP_INI_ALL,            OnUpdateStringUnempty,  arg_separator.output,   php_core_globals,       core_globals)
     525             :         STD_PHP_INI_ENTRY("arg_separator.input",      "&",              PHP_INI_SYSTEM|PHP_INI_PERDIR,  OnUpdateStringUnempty,  arg_separator.input,    php_core_globals,       core_globals)
     526             : 
     527             :         STD_PHP_INI_ENTRY("auto_append_file",         NULL,           PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateString,                 auto_append_file,               php_core_globals,       core_globals)
     528             :         STD_PHP_INI_ENTRY("auto_prepend_file",                NULL,           PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateString,                 auto_prepend_file,              php_core_globals,       core_globals)
     529             :         STD_PHP_INI_ENTRY("doc_root",                         NULL,           PHP_INI_SYSTEM,         OnUpdateStringUnempty,  doc_root,                               php_core_globals,       core_globals)
     530             :         STD_PHP_INI_ENTRY("default_charset",          PHP_DEFAULT_CHARSET,    PHP_INI_ALL,    OnUpdateString,                 default_charset,                sapi_globals_struct, sapi_globals)
     531             :         STD_PHP_INI_ENTRY("default_mimetype",         SAPI_DEFAULT_MIMETYPE,  PHP_INI_ALL,    OnUpdateString,                 default_mimetype,               sapi_globals_struct, sapi_globals)
     532             :         STD_PHP_INI_ENTRY("internal_encoding",                NULL,                   PHP_INI_ALL,    OnUpdateInternalEncoding,       internal_encoding,      php_core_globals, core_globals)
     533             :         STD_PHP_INI_ENTRY("input_encoding",                   NULL,                   PHP_INI_ALL,    OnUpdateInputEncoding,                          input_encoding,         php_core_globals, core_globals)
     534             :         STD_PHP_INI_ENTRY("output_encoding",          NULL,                   PHP_INI_ALL,    OnUpdateOutputEncoding,                         output_encoding,        php_core_globals, core_globals)
     535             :         STD_PHP_INI_ENTRY("error_log",                                NULL,           PHP_INI_ALL,            OnUpdateErrorLog,                       error_log,                              php_core_globals,       core_globals)
     536             :         STD_PHP_INI_ENTRY("extension_dir",                    PHP_EXTENSION_DIR,              PHP_INI_SYSTEM,         OnUpdateStringUnempty,  extension_dir,                  php_core_globals,       core_globals)
     537             :         STD_PHP_INI_ENTRY("sys_temp_dir",                     NULL,           PHP_INI_SYSTEM,         OnUpdateStringUnempty,  sys_temp_dir,                   php_core_globals,       core_globals)
     538             :         STD_PHP_INI_ENTRY("include_path",                     PHP_INCLUDE_PATH,               PHP_INI_ALL,            OnUpdateStringUnempty,  include_path,                   php_core_globals,       core_globals)
     539             :         PHP_INI_ENTRY("max_execution_time",                   "30",         PHP_INI_ALL,                    OnUpdateTimeout)
     540             :         STD_PHP_INI_ENTRY("open_basedir",                     NULL,           PHP_INI_ALL,            OnUpdateBaseDir,                        open_basedir,                   php_core_globals,       core_globals)
     541             : 
     542             :         STD_PHP_INI_BOOLEAN("file_uploads",                   "1",          PHP_INI_SYSTEM,         OnUpdateBool,                   file_uploads,                   php_core_globals,       core_globals)
     543             :         STD_PHP_INI_ENTRY("upload_max_filesize",      "2M",         PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateLong,                   upload_max_filesize,    php_core_globals,       core_globals)
     544             :         STD_PHP_INI_ENTRY("post_max_size",                    "8M",         PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateLong,                   post_max_size,                  sapi_globals_struct,sapi_globals)
     545             :         STD_PHP_INI_ENTRY("upload_tmp_dir",                   NULL,           PHP_INI_SYSTEM,         OnUpdateStringUnempty,  upload_tmp_dir,                 php_core_globals,       core_globals)
     546             :         STD_PHP_INI_ENTRY("max_input_nesting_level", "64",          PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateLongGEZero,     max_input_nesting_level,                        php_core_globals,       core_globals)
     547             :         STD_PHP_INI_ENTRY("max_input_vars",                   "1000",               PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateLongGEZero,     max_input_vars,                                         php_core_globals,       core_globals)
     548             : 
     549             :         STD_PHP_INI_ENTRY("user_dir",                         NULL,           PHP_INI_SYSTEM,         OnUpdateString,                 user_dir,                               php_core_globals,       core_globals)
     550             :         STD_PHP_INI_ENTRY("variables_order",          "EGPCS",      PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateStringUnempty,  variables_order,                php_core_globals,       core_globals)
     551             :         STD_PHP_INI_ENTRY("request_order",                    NULL,           PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateString, request_order,          php_core_globals,       core_globals)
     552             : 
     553             :         STD_PHP_INI_ENTRY("error_append_string",      NULL,           PHP_INI_ALL,            OnUpdateString,                 error_append_string,    php_core_globals,       core_globals)
     554             :         STD_PHP_INI_ENTRY("error_prepend_string",     NULL,           PHP_INI_ALL,            OnUpdateString,                 error_prepend_string,   php_core_globals,       core_globals)
     555             : 
     556             :         PHP_INI_ENTRY("SMTP",                                         "localhost",PHP_INI_ALL,              NULL)
     557             :         PHP_INI_ENTRY("smtp_port",                                    "25",         PHP_INI_ALL,            NULL)
     558             :         STD_PHP_INI_BOOLEAN("mail.add_x_header",                      "0",          PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,                   mail_x_header,                  php_core_globals,       core_globals)
     559             :         STD_PHP_INI_ENTRY("mail.log",                                 NULL,           PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateMailLog,                        mail_log,                       php_core_globals,       core_globals)
     560             :         PHP_INI_ENTRY("browscap",                                     NULL,           PHP_INI_SYSTEM,         OnChangeBrowscap)
     561             :         PHP_INI_ENTRY("memory_limit",                         "128M",               PHP_INI_ALL,            OnChangeMemoryLimit)
     562             :         PHP_INI_ENTRY("precision",                                    "14",         PHP_INI_ALL,            OnSetPrecision)
     563             :         PHP_INI_ENTRY("sendmail_from",                                NULL,           PHP_INI_ALL,            NULL)
     564             :         PHP_INI_ENTRY("sendmail_path",        DEFAULT_SENDMAIL_PATH,  PHP_INI_SYSTEM,         NULL)
     565             :         PHP_INI_ENTRY("mail.force_extra_parameters",NULL,             PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnChangeMailForceExtra)
     566             :         PHP_INI_ENTRY("disable_functions",                    "",                   PHP_INI_SYSTEM,         NULL)
     567             :         PHP_INI_ENTRY("disable_classes",                      "",                   PHP_INI_SYSTEM,         NULL)
     568             :         PHP_INI_ENTRY("max_file_uploads",                     "20",                 PHP_INI_SYSTEM|PHP_INI_PERDIR,          NULL)
     569             : 
     570             :         STD_PHP_INI_BOOLEAN("allow_url_fopen",                "1",          PHP_INI_SYSTEM,         OnUpdateBool,           allow_url_fopen,                php_core_globals,               core_globals)
     571             :         STD_PHP_INI_BOOLEAN("allow_url_include",      "0",          PHP_INI_SYSTEM,         OnUpdateBool,           allow_url_include,              php_core_globals,               core_globals)
     572             :         STD_PHP_INI_BOOLEAN("enable_post_data_reading",       "1",  PHP_INI_SYSTEM|PHP_INI_PERDIR,  OnUpdateBool,   enable_post_data_reading,       php_core_globals,       core_globals)
     573             : 
     574             :         STD_PHP_INI_ENTRY("realpath_cache_size",      "16K",                PHP_INI_SYSTEM,         OnUpdateLong,   realpath_cache_size_limit,      virtual_cwd_globals,    cwd_globals)
     575             :         STD_PHP_INI_ENTRY("realpath_cache_ttl",               "120",                PHP_INI_SYSTEM,         OnUpdateLong,   realpath_cache_ttl,                     virtual_cwd_globals,    cwd_globals)
     576             : 
     577             :         STD_PHP_INI_ENTRY("user_ini.filename",                ".user.ini",  PHP_INI_SYSTEM,         OnUpdateString,         user_ini_filename,      php_core_globals,               core_globals)
     578             :         STD_PHP_INI_ENTRY("user_ini.cache_ttl",               "300",                        PHP_INI_SYSTEM,         OnUpdateLong,           user_ini_cache_ttl,     php_core_globals,               core_globals)
     579             :         STD_PHP_INI_BOOLEAN("exit_on_timeout",                "0",          PHP_INI_ALL,            OnUpdateBool,                   exit_on_timeout,                        php_core_globals,       core_globals)
     580             : #ifdef PHP_WIN32
     581             :         STD_PHP_INI_BOOLEAN("windows.show_crt_warning",               "0",          PHP_INI_ALL,            OnUpdateBool,                   windows_show_crt_warning,                       php_core_globals,       core_globals)
     582             : #endif
     583             : PHP_INI_END()
     584             : /* }}} */
     585             : 
     586             : /* True globals (no need for thread safety */
     587             : /* But don't make them a single int bitfield */
     588             : static int module_initialized = 0;
     589             : static int module_startup = 1;
     590             : static int module_shutdown = 0;
     591             : 
     592             : /* {{{ php_during_module_startup */
     593      201034 : static int php_during_module_startup(void)
     594             : {
     595      201034 :         return module_startup;
     596             : }
     597             : /* }}} */
     598             : 
     599             : /* {{{ php_during_module_shutdown */
     600      201025 : static int php_during_module_shutdown(void)
     601             : {
     602      201025 :         return module_shutdown;
     603             : }
     604             : /* }}} */
     605             : 
     606             : /* {{{ php_get_module_initialized
     607             :  */
     608           0 : PHPAPI int php_get_module_initialized(void)
     609             : {
     610           0 :         return module_initialized;
     611             : }
     612             : /* }}} */
     613             : 
     614             : /* {{{ php_log_err
     615             :  */
     616          13 : PHPAPI void php_log_err(char *log_message)
     617             : {
     618          13 :         int fd = -1;
     619             :         time_t error_time;
     620             : 
     621          13 :         if (PG(in_error_log)) {
     622             :                 /* prevent recursive invocation */
     623           0 :                 return;
     624             :         }
     625          13 :         PG(in_error_log) = 1;
     626             : 
     627             :         /* Try to use the specified logging location. */
     628          13 :         if (PG(error_log) != NULL) {
     629             : #ifdef HAVE_SYSLOG_H
     630          10 :                 if (!strcmp(PG(error_log), "syslog")) {
     631           0 :                         php_syslog(LOG_NOTICE, "%s", log_message);
     632           0 :                         PG(in_error_log) = 0;
     633           0 :                         return;
     634             :                 }
     635             : #endif
     636          10 :                 fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
     637          10 :                 if (fd != -1) {
     638             :                         char *tmp;
     639             :                         size_t len;
     640             :                         zend_string *error_time_str;
     641             : 
     642           2 :                         time(&error_time);
     643             : #ifdef ZTS
     644             :                         if (!php_during_module_startup()) {
     645             :                                 error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1);
     646             :                         } else {
     647             :                                 error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 0);
     648             :                         }
     649             : #else
     650           2 :                         error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1);
     651             : #endif
     652           2 :                         len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str->val, log_message, PHP_EOL);
     653             : #ifdef PHP_WIN32
     654             :                         php_flock(fd, 2);
     655             :                         /* XXX should eventually write in a loop if len > UINT_MAX */
     656             :                         php_ignore_value(write(fd, tmp, (unsigned)len));
     657             : #else
     658           2 :                         php_ignore_value(write(fd, tmp, len));
     659             : #endif
     660           2 :                         efree(tmp);
     661             :                         zend_string_free(error_time_str);
     662           2 :                         close(fd);
     663           2 :                         PG(in_error_log) = 0;
     664           2 :                         return;
     665             :                 }
     666             :         }
     667             : 
     668             :         /* Otherwise fall back to the default logging location, if we have one */
     669             : 
     670          11 :         if (sapi_module.log_message) {
     671          11 :                 sapi_module.log_message(log_message);
     672             :         }
     673          11 :         PG(in_error_log) = 0;
     674             : }
     675             : /* }}} */
     676             : 
     677             : /* {{{ php_write
     678             :    wrapper for modules to use PHPWRITE */
     679         671 : PHPAPI size_t php_write(void *buf, size_t size)
     680             : {
     681         671 :         return PHPWRITE(buf, size);
     682             : }
     683             : /* }}} */
     684             : 
     685             : /* {{{ php_printf
     686             :  */
     687      421465 : PHPAPI size_t php_printf(const char *format, ...)
     688             : {
     689             :         va_list args;
     690             :         size_t ret;
     691             :         char *buffer;
     692             :         size_t size;
     693             : 
     694      421465 :         va_start(args, format);
     695      421465 :         size = vspprintf(&buffer, 0, format, args);
     696      421465 :         ret = PHPWRITE(buffer, size);
     697      421461 :         efree(buffer);
     698      421461 :         va_end(args);
     699             : 
     700      421461 :         return ret;
     701             : }
     702             : /* }}} */
     703             : 
     704             : /* {{{ php_verror */
     705             : /* php_verror is called from php_error_docref<n> functions.
     706             :  * Its purpose is to unify error messages and automatically generate clickable
     707             :  * html error messages if correcponding ini setting (html_errors) is activated.
     708             :  * See: CODING_STANDARDS for details.
     709             :  */
     710      201034 : PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args)
     711             : {
     712      201034 :         zend_string *replace_buffer = NULL, *replace_origin = NULL;
     713      201034 :         char *buffer = NULL, *docref_buf = NULL, *target = NULL;
     714      201034 :         char *docref_target = "", *docref_root = "";
     715             :         char *p;
     716      201034 :         int buffer_len = 0;
     717      201034 :         const char *space = "";
     718      201034 :         const char *class_name = "";
     719             :         const char *function;
     720             :         int origin_len;
     721             :         char *origin;
     722             :         char *message;
     723      201034 :         int is_function = 0;
     724             : 
     725             :         /* get error text into buffer and escape for html if necessary */
     726      201034 :         buffer_len = (int)vspprintf(&buffer, 0, format, args);
     727             : 
     728      201034 :         if (PG(html_errors)) {
     729           6 :                 replace_buffer = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, NULL);
     730           6 :                 efree(buffer);
     731           6 :                 buffer = replace_buffer->val;
     732           6 :                 buffer_len = (int)replace_buffer->len;
     733             :         }
     734             : 
     735             :         /* which function caused the problem if any at all */
     736      201034 :         if (php_during_module_startup()) {
     737           9 :                 function = "PHP Startup";
     738      201025 :         } else if (php_during_module_shutdown()) {
     739           0 :                 function = "PHP Shutdown";
     740      603668 :         } else if (EG(current_execute_data) &&
     741      201011 :                                 EG(current_execute_data)->func &&
     742      201011 :                                 ZEND_USER_CODE(EG(current_execute_data)->func->common.type) &&
     743         276 :                                 EG(current_execute_data)->opline &&
     744         276 :                                 EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
     745             :         ) {
     746          69 :                 switch (EG(current_execute_data)->opline->extended_value) {
     747             :                         case ZEND_EVAL:
     748           0 :                                 function = "eval";
     749           0 :                                 is_function = 1;
     750           0 :                                 break;
     751             :                         case ZEND_INCLUDE:
     752          64 :                                 function = "include";
     753          64 :                                 is_function = 1;
     754          64 :                                 break;
     755             :                         case ZEND_INCLUDE_ONCE:
     756           0 :                                 function = "include_once";
     757           0 :                                 is_function = 1;
     758           0 :                                 break;
     759             :                         case ZEND_REQUIRE:
     760           1 :                                 function = "require";
     761           1 :                                 is_function = 1;
     762           1 :                                 break;
     763             :                         case ZEND_REQUIRE_ONCE:
     764           4 :                                 function = "require_once";
     765           4 :                                 is_function = 1;
     766           4 :                                 break;
     767             :                         default:
     768           0 :                                 function = "Unknown";
     769             :                 }
     770             :         } else {
     771      200956 :                 function = get_active_function_name();
     772      200970 :                 if (!function || !strlen(function)) {
     773          14 :                         function = "Unknown";
     774             :                 } else {
     775      200942 :                         is_function = 1;
     776      200942 :                         class_name = get_active_class_name(&space);
     777             :                 }
     778             :         }
     779             : 
     780             :         /* if we still have memory then format the origin */
     781      201034 :         if (is_function) {
     782      201011 :                 origin_len = (int)spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
     783             :         } else {
     784          23 :                 origin_len = (int)spprintf(&origin, 0, "%s", function);
     785             :         }
     786             : 
     787      201034 :         if (PG(html_errors)) {
     788           6 :                 replace_origin = php_escape_html_entities((unsigned char*)origin, origin_len, 0, ENT_COMPAT, NULL);
     789           6 :                 efree(origin);
     790           6 :                 origin = replace_origin->val;
     791             :         }
     792             : 
     793             :         /* origin and buffer available, so lets come up with the error message */
     794      201034 :         if (docref && docref[0] == '#') {
     795           0 :                 docref_target = strchr(docref, '#');
     796           0 :                 docref = NULL;
     797             :         }
     798             : 
     799             :         /* no docref given but function is known (the default) */
     800      201034 :         if (!docref && is_function) {
     801             :                 int doclen;
     802      401840 :                 while (*function == '_') {
     803         188 :                         function++;
     804             :                 }
     805      200826 :                 if (space[0] == '\0') {
     806      199525 :                         doclen = (int)spprintf(&docref_buf, 0, "function.%s", function);
     807             :                 } else {
     808        1301 :                         doclen = (int)spprintf(&docref_buf, 0, "%s.%s", class_name, function);
     809             :                 }
     810      410098 :                 while((p = strchr(docref_buf, '_')) != NULL) {
     811        8446 :                         *p = '-';
     812             :                 }
     813      200826 :                 docref = php_strtolower(docref_buf, doclen);
     814             :         }
     815             : 
     816             :         /* we have a docref for a function AND
     817             :          * - we show errors in html mode AND
     818             :          * - the user wants to see the links
     819             :          */
     820      201036 :         if (docref && is_function && PG(html_errors) && strlen(PG(docref_root))) {
     821           2 :                 if (strncmp(docref, "http://", 7)) {
     822             :                         /* We don't have 'http://' so we use docref_root */
     823             : 
     824             :                         char *ref;  /* temp copy for duplicated docref */
     825             : 
     826           2 :                         docref_root = PG(docref_root);
     827             : 
     828           2 :                         ref = estrdup(docref);
     829           2 :                         if (docref_buf) {
     830           1 :                                 efree(docref_buf);
     831             :                         }
     832           2 :                         docref_buf = ref;
     833             :                         /* strip of the target if any */
     834           2 :                         p = strrchr(ref, '#');
     835           2 :                         if (p) {
     836           0 :                                 target = estrdup(p);
     837           0 :                                 if (target) {
     838           0 :                                         docref_target = target;
     839           0 :                                         *p = '\0';
     840             :                                 }
     841             :                         }
     842             :                         /* add the extension if it is set in ini */
     843           2 :                         if (PG(docref_ext) && strlen(PG(docref_ext))) {
     844           2 :                                 spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext));
     845           2 :                                 efree(ref);
     846             :                         }
     847           2 :                         docref = docref_buf;
     848             :                 }
     849             :                 /* display html formatted or only show the additional links */
     850           2 :                 if (PG(html_errors)) {
     851           2 :                         spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer);
     852             :                 } else {
     853           0 :                         spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer);
     854             :                 }
     855           2 :                 if (target) {
     856           0 :                         efree(target);
     857             :                 }
     858             :         } else {
     859      201032 :                 spprintf(&message, 0, "%s: %s", origin, buffer);
     860             :         }
     861      201034 :         if (replace_origin) {
     862             :                 zend_string_free(replace_origin);
     863             :         } else {
     864      201028 :                 efree(origin);
     865             :         }
     866      201034 :         if (docref_buf) {
     867      200827 :                 efree(docref_buf);
     868             :         }
     869             : 
     870      213966 :         if (PG(track_errors) && module_initialized && EG(valid_symbol_table) &&
     871         735 :                         (Z_TYPE(EG(user_error_handler)) == IS_UNDEF || !(EG(user_error_handler_error_reporting) & type))) {
     872             :                 zval tmp;
     873       22952 :                 ZVAL_STRINGL(&tmp, buffer, buffer_len);
     874       11476 :                 if (EG(current_execute_data)) {
     875       11462 :                         if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0) == FAILURE) {
     876        2256 :                                 zval_ptr_dtor(&tmp);
     877             :                         }
     878             :                 } else {
     879          14 :                         zend_hash_str_update_ind(&EG(symbol_table), "php_errormsg", sizeof("php_errormsg")-1, &tmp);
     880             :                 }
     881             :         }
     882      201034 :         if (replace_buffer) {
     883             :                 zend_string_free(replace_buffer);
     884             :         } else {
     885      201028 :                 efree(buffer);
     886             :         }
     887             : 
     888      201034 :         php_error(type, "%s", message);
     889      200999 :         efree(message);
     890      200999 : }
     891             : /* }}} */
     892             : 
     893             : /* {{{ php_error_docref0 */
     894             : /* See: CODING_STANDARDS for details. */
     895       11261 : PHPAPI void php_error_docref0(const char *docref, int type, const char *format, ...)
     896             : {
     897             :         va_list args;
     898             : 
     899       11261 :         va_start(args, format);
     900       11261 :         php_verror(docref, "", type, format, args);
     901       11226 :         va_end(args);
     902       11226 : }
     903             : /* }}} */
     904             : 
     905             : /* {{{ php_error_docref1 */
     906             : /* See: CODING_STANDARDS for details. */
     907      189641 : PHPAPI void php_error_docref1(const char *docref, const char *param1, int type, const char *format, ...)
     908             : {
     909             :         va_list args;
     910             : 
     911      189641 :         va_start(args, format);
     912      189641 :         php_verror(docref, param1, type, format, args);
     913      189641 :         va_end(args);
     914      189641 : }
     915             : /* }}} */
     916             : 
     917             : /* {{{ php_error_docref2 */
     918             : /* See: CODING_STANDARDS for details. */
     919          44 : PHPAPI void php_error_docref2(const char *docref, const char *param1, const char *param2, int type, const char *format, ...)
     920             : {
     921             :         char *params;
     922             :         va_list args;
     923             : 
     924          44 :         spprintf(&params, 0, "%s,%s", param1, param2);
     925          44 :         va_start(args, format);
     926          44 :         php_verror(docref, params ? params : "...", type, format, args);
     927          44 :         va_end(args);
     928          44 :         if (params) {
     929          44 :                 efree(params);
     930             :         }
     931          44 : }
     932             : /* }}} */
     933             : 
     934             : #ifdef PHP_WIN32
     935             : #define PHP_WIN32_ERROR_MSG_BUFFER_SIZE 512
     936             : PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2) {
     937             :         if (error == 0) {
     938             :                 php_error_docref2(NULL, param1, param2, E_WARNING, "%s", strerror(errno));
     939             :         } else {
     940             :                 char buf[PHP_WIN32_ERROR_MSG_BUFFER_SIZE + 1];
     941             :                 int buf_len;
     942             : 
     943             :                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL);
     944             :                 buf_len = (int)strlen(buf);
     945             :                 if (buf_len >= 2) {
     946             :                         buf[buf_len - 1] = '\0';
     947             :                         buf[buf_len - 2] = '\0';
     948             :                 }
     949             :                 php_error_docref2(NULL, param1, param2, E_WARNING, "%s (code: %lu)", (char *)buf, error);
     950             :         }
     951             : }
     952             : #undef PHP_WIN32_ERROR_MSG_BUFFER_SIZE
     953             : #endif
     954             : 
     955             : /* {{{ php_html_puts */
     956         216 : PHPAPI void php_html_puts(const char *str, size_t size)
     957             : {
     958         216 :         zend_html_puts(str, size);
     959         216 : }
     960             : /* }}} */
     961             : 
     962             : /* {{{ php_error_cb
     963             :  extended error handling function */
     964      376359 : static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
     965             : {
     966             :         char *buffer;
     967             :         int buffer_len, display;
     968             : 
     969      376359 :         buffer_len = (int)vspprintf(&buffer, PG(log_errors_max_len), format, args);
     970             : 
     971             :         /* check for repeated errors to be ignored */
     972      376359 :         if (PG(ignore_repeated_errors) && PG(last_error_message)) {
     973             :                 /* no check for PG(last_error_file) is needed since it cannot
     974             :                  * be NULL if PG(last_error_message) is not NULL */
     975           0 :                 if (strcmp(PG(last_error_message), buffer)
     976           0 :                         || (!PG(ignore_repeated_source)
     977           0 :                                 && ((PG(last_error_lineno) != (int)error_lineno)
     978           0 :                                         || strcmp(PG(last_error_file), error_filename)))) {
     979           0 :                         display = 1;
     980             :                 } else {
     981           0 :                         display = 0;
     982             :                 }
     983             :         } else {
     984      376359 :                 display = 1;
     985             :         }
     986             : 
     987             :         /* store the error if it has changed */
     988      376359 :         if (display) {
     989             : #ifdef ZEND_SIGNALS
     990             :                 HANDLE_BLOCK_INTERRUPTIONS();
     991             : #endif
     992      376359 :                 if (PG(last_error_message)) {
     993      371207 :                         free(PG(last_error_message));
     994      371207 :                         PG(last_error_message) = NULL;
     995             :                 }
     996      376359 :                 if (PG(last_error_file)) {
     997      371207 :                         free(PG(last_error_file));
     998      371207 :                         PG(last_error_file) = NULL;
     999             :                 }
    1000             : #ifdef ZEND_SIGNALS
    1001             :                 HANDLE_UNBLOCK_INTERRUPTIONS();
    1002             : #endif
    1003      376359 :                 if (!error_filename) {
    1004           2 :                         error_filename = "Unknown";
    1005             :                 }
    1006      376359 :                 PG(last_error_type) = type;
    1007      376359 :                 PG(last_error_message) = strdup(buffer);
    1008      376359 :                 PG(last_error_file) = strdup(error_filename);
    1009      376359 :                 PG(last_error_lineno) = error_lineno;
    1010             :         }
    1011             : 
    1012             :         /* according to error handling mode, suppress error, throw exception or show it */
    1013      376359 :         if (EG(error_handling) != EH_NORMAL) {
    1014          90 :                 switch (type) {
    1015             :                         case E_ERROR:
    1016             :                         case E_CORE_ERROR:
    1017             :                         case E_COMPILE_ERROR:
    1018             :                         case E_USER_ERROR:
    1019             :                         case E_PARSE:
    1020             :                                 /* fatal errors are real errors and cannot be made exceptions */
    1021           0 :                                 break;
    1022             :                         case E_STRICT:
    1023             :                         case E_DEPRECATED:
    1024             :                         case E_USER_DEPRECATED:
    1025             :                                 /* for the sake of BC to old damaged code */
    1026           0 :                                 break;
    1027             :                         case E_NOTICE:
    1028             :                         case E_USER_NOTICE:
    1029             :                                 /* notices are no errors and are not treated as such like E_WARNINGS */
    1030           1 :                                 break;
    1031             :                         default:
    1032             :                                 /* throw an exception if we are in EH_THROW mode
    1033             :                                  * but DO NOT overwrite a pending exception
    1034             :                                  */
    1035          89 :                                 if (EG(error_handling) == EH_THROW && !EG(exception)) {
    1036          82 :                                         zend_throw_error_exception(EG(exception_class), buffer, 0, type);
    1037             :                                 }
    1038          89 :                                 efree(buffer);
    1039          89 :                                 return;
    1040             :                 }
    1041             :         }
    1042             : 
    1043             :         /* display/log the error if necessary */
    1044      419855 :         if (display && (EG(error_reporting) & type || (type & E_CORE))
    1045       43585 :                 && (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
    1046             :                 char *error_type_str;
    1047             : 
    1048       20885 :                 switch (type) {
    1049             :                         case E_ERROR:
    1050             :                         case E_CORE_ERROR:
    1051             :                         case E_COMPILE_ERROR:
    1052             :                         case E_USER_ERROR:
    1053         848 :                                 error_type_str = "Fatal error";
    1054         848 :                                 break;
    1055             :                         case E_RECOVERABLE_ERROR:
    1056          27 :                                 error_type_str = "Catchable fatal error";
    1057          27 :                                 break;
    1058             :                         case E_WARNING:
    1059             :                         case E_CORE_WARNING:
    1060             :                         case E_COMPILE_WARNING:
    1061             :                         case E_USER_WARNING:
    1062       17810 :                                 error_type_str = "Warning";
    1063       17810 :                                 break;
    1064             :                         case E_PARSE:
    1065          42 :                                 error_type_str = "Parse error";
    1066          42 :                                 break;
    1067             :                         case E_NOTICE:
    1068             :                         case E_USER_NOTICE:
    1069        2056 :                                 error_type_str = "Notice";
    1070        2056 :                                 break;
    1071             :                         case E_STRICT:
    1072          14 :                                 error_type_str = "Strict Standards";
    1073          14 :                                 break;
    1074             :                         case E_DEPRECATED:
    1075             :                         case E_USER_DEPRECATED:
    1076          88 :                                 error_type_str = "Deprecated";
    1077          88 :                                 break;
    1078             :                         default:
    1079           0 :                                 error_type_str = "Unknown error";
    1080             :                                 break;
    1081             :                 }
    1082             : 
    1083       20885 :                 if (!module_initialized || PG(log_errors)) {
    1084             :                         char *log_buffer;
    1085             : #ifdef PHP_WIN32
    1086             :                         if (type == E_CORE_ERROR || type == E_CORE_WARNING) {
    1087             :                                 syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, buffer, GetCommandLine());
    1088             :                         }
    1089             : #endif
    1090          12 :                         spprintf(&log_buffer, 0, "PHP %s:  %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
    1091          12 :                         php_log_err(log_buffer);
    1092          12 :                         efree(log_buffer);
    1093             :                 }
    1094             : 
    1095       20885 :                 if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) {
    1096       20877 :                         if (PG(xmlrpc_errors)) {
    1097           0 :                                 php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%pd</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno);
    1098             :                         } else {
    1099       20877 :                                 char *prepend_string = INI_STR("error_prepend_string");
    1100       20877 :                                 char *append_string = INI_STR("error_append_string");
    1101             : 
    1102       20877 :                                 if (PG(html_errors)) {
    1103          10 :                                         if (type == E_ERROR || type == E_PARSE) {
    1104           2 :                                                 zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, NULL);
    1105           2 :                                                 php_printf("%s<br />\n<b>%s</b>:  %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buf->val, error_filename, error_lineno, STR_PRINT(append_string));
    1106             :                                                 zend_string_free(buf);
    1107             :                                         } else {
    1108           6 :                                                 php_printf("%s<br />\n<b>%s</b>:  %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
    1109             :                                         }
    1110             :                                 } else {
    1111             :                                         /* Write CLI/CGI errors to stderr if display_errors = "stderr" */
    1112       41673 :                                         if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) &&
    1113       20804 :                                                 PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
    1114             :                                         ) {
    1115             : #ifdef PHP_WIN32
    1116             :                                                 fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno);
    1117             :                                                 fflush(stderr);
    1118             : #else
    1119           0 :                                                 fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno);
    1120             : #endif
    1121             :                                         } else {
    1122       20869 :                                                 php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
    1123             :                                         }
    1124             :                                 }
    1125             :                         }
    1126             :                 }
    1127             : #if ZEND_DEBUG
    1128             :                 if (PG(report_zend_debug)) {
    1129             :                         zend_bool trigger_break;
    1130             : 
    1131             :                         switch (type) {
    1132             :                                 case E_ERROR:
    1133             :                                 case E_CORE_ERROR:
    1134             :                                 case E_COMPILE_ERROR:
    1135             :                                 case E_USER_ERROR:
    1136             :                                         trigger_break=1;
    1137             :                                         break;
    1138             :                                 default:
    1139             :                                         trigger_break=0;
    1140             :                                         break;
    1141             :                         }
    1142             :                         zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
    1143             :                 }
    1144             : #endif
    1145             :         }
    1146             : 
    1147             :         /* Bail out if we can't recover */
    1148      376267 :         switch (type) {
    1149             :                 case E_CORE_ERROR:
    1150           5 :                         if(!module_initialized) {
    1151             :                                 /* bad error in module startup - no way we can live with this */
    1152           0 :                                 exit(-2);
    1153             :                         }
    1154             :                 /* no break - intentionally */
    1155             :                 case E_ERROR:
    1156             :                 case E_RECOVERABLE_ERROR:
    1157             :                 case E_PARSE:
    1158             :                 case E_COMPILE_ERROR:
    1159             :                 case E_USER_ERROR:
    1160         938 :                         EG(exit_status) = 255;
    1161         938 :                         if (module_initialized) {
    1162         977 :                                 if (!PG(display_errors) &&
    1163          20 :                                     !SG(headers_sent) &&
    1164          19 :                                         SG(sapi_headers).http_response_code == 200
    1165             :                                 ) {
    1166           0 :                                         sapi_header_line ctr = {0};
    1167             : 
    1168           0 :                                         ctr.line = "HTTP/1.0 500 Internal Server Error";
    1169           0 :                                         ctr.line_len = sizeof("HTTP/1.0 500 Internal Server Error") - 1;
    1170           0 :                                         sapi_header_op(SAPI_HEADER_REPLACE, &ctr);
    1171             :                                 }
    1172             :                                 /* the parser would return 1 (failure), we can bail out nicely */
    1173         938 :                                 if (type == E_PARSE) {
    1174          44 :                                         CG(parse_error) = 0;
    1175             :                                 } else {
    1176             :                                         /* restore memory limit */
    1177         894 :                                         zend_set_memory_limit(PG(memory_limit));
    1178         894 :                                         efree(buffer);
    1179         894 :                                         zend_objects_store_mark_destructed(&EG(objects_store));
    1180         894 :                                         zend_bailout();
    1181           0 :                                         return;
    1182             :                                 }
    1183             :                         }
    1184             :                         break;
    1185             :         }
    1186             : 
    1187             :         /* Log if necessary */
    1188      375373 :         if (!display) {
    1189           0 :                 efree(buffer);
    1190           0 :                 return;
    1191             :         }
    1192             : 
    1193      375373 :         if (PG(track_errors) && module_initialized && EG(valid_symbol_table)) {
    1194             :                 zval tmp;
    1195             : 
    1196       51670 :                 ZVAL_STRINGL(&tmp, buffer, buffer_len);
    1197       25835 :                 if (EG(current_execute_data)) {
    1198       25675 :                         if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0) == FAILURE) {
    1199        2709 :                                 zval_ptr_dtor(&tmp);
    1200             :                         }
    1201             :                 } else {
    1202         160 :                         zend_hash_str_update_ind(&EG(symbol_table), "php_errormsg", sizeof("php_errormsg")-1, &tmp);
    1203             :                 }
    1204             :         }
    1205             : 
    1206      375373 :         efree(buffer);
    1207             : }
    1208             : /* }}} */
    1209             : 
    1210             : /* {{{ php_get_current_user
    1211             :  */
    1212          11 : PHPAPI char *php_get_current_user(void)
    1213             : {
    1214             :         zend_stat_t *pstat;
    1215             : 
    1216          11 :         if (SG(request_info).current_user) {
    1217           2 :                 return SG(request_info).current_user;
    1218             :         }
    1219             : 
    1220             :         /* FIXME: I need to have this somehow handled if
    1221             :         USE_SAPI is defined, because cgi will also be
    1222             :         interfaced in USE_SAPI */
    1223             : 
    1224           9 :         pstat = sapi_get_stat();
    1225             : 
    1226           9 :         if (!pstat) {
    1227           0 :                 return "";
    1228             :         } else {
    1229             : #ifdef PHP_WIN32
    1230             :                 char name[256];
    1231             :                 DWORD len = sizeof(name)-1;
    1232             : 
    1233             :                 if (!GetUserName(name, &len)) {
    1234             :                         return "";
    1235             :                 }
    1236             :                 name[len] = '\0';
    1237             :                 SG(request_info).current_user_length = len;
    1238             :                 SG(request_info).current_user = estrndup(name, len);
    1239             :                 return SG(request_info).current_user;
    1240             : #else
    1241             :                 struct passwd *pwd;
    1242             : #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
    1243             :                 struct passwd _pw;
    1244             :                 struct passwd *retpwptr = NULL;
    1245             :                 int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
    1246             :                 char *pwbuf;
    1247             : 
    1248             :                 if (pwbuflen < 1) {
    1249             :                         return "";
    1250             :                 }
    1251             :                 pwbuf = emalloc(pwbuflen);
    1252             :                 if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
    1253             :                         efree(pwbuf);
    1254             :                         return "";
    1255             :                 }
    1256             :                 if (retpwptr == NULL) {
    1257             :                         efree(pwbuf);
    1258             :                         return "";
    1259             :                 }
    1260             :                 pwd = &_pw;
    1261             : #else
    1262           9 :                 if ((pwd=getpwuid(pstat->st_uid))==NULL) {
    1263           0 :                         return "";
    1264             :                 }
    1265             : #endif
    1266           9 :                 SG(request_info).current_user_length = strlen(pwd->pw_name);
    1267           9 :                 SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
    1268             : #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
    1269             :                 efree(pwbuf);
    1270             : #endif
    1271           9 :                 return SG(request_info).current_user;
    1272             : #endif
    1273             :         }
    1274             : }
    1275             : /* }}} */
    1276             : 
    1277             : /* {{{ proto bool set_time_limit(int seconds)
    1278             :    Sets the maximum time a script can run */
    1279          28 : PHP_FUNCTION(set_time_limit)
    1280             : {
    1281             :         zend_long new_timeout;
    1282             :         char *new_timeout_str;
    1283             :         int new_timeout_strlen;
    1284             :         zend_string *key;
    1285             : 
    1286          28 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &new_timeout) == FAILURE) {
    1287           0 :                 return;
    1288             :         }
    1289             : 
    1290          28 :         new_timeout_strlen = (int)zend_spprintf(&new_timeout_str, 0, ZEND_LONG_FMT, new_timeout);
    1291             : 
    1292          28 :         key = zend_string_init("max_execution_time", sizeof("max_execution_time")-1, 0);
    1293          28 :         if (zend_alter_ini_entry_chars_ex(key, new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == SUCCESS) {
    1294          28 :                 RETVAL_TRUE;
    1295             :         } else {
    1296           0 :                 RETVAL_FALSE;
    1297             :         }
    1298             :         zend_string_release(key);
    1299          28 :         efree(new_timeout_str);
    1300             : }
    1301             : /* }}} */
    1302             : 
    1303             : /* {{{ php_fopen_wrapper_for_zend
    1304             :  */
    1305           0 : static FILE *php_fopen_wrapper_for_zend(const char *filename, zend_string **opened_path)
    1306             : {
    1307           0 :         return php_stream_open_wrapper_as_file((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
    1308             : }
    1309             : /* }}} */
    1310             : 
    1311        8443 : static void php_zend_stream_closer(void *handle) /* {{{ */
    1312             : {
    1313        8443 :         php_stream_close((php_stream*)handle);
    1314        8443 : }
    1315             : /* }}} */
    1316             : 
    1317        8156 : static void php_zend_stream_mmap_closer(void *handle) /* {{{ */
    1318             : {
    1319        8156 :         php_stream_mmap_unmap((php_stream*)handle);
    1320        8156 :         php_zend_stream_closer(handle);
    1321        8156 : }
    1322             : /* }}} */
    1323             : 
    1324        8763 : static size_t php_zend_stream_fsizer(void *handle) /* {{{ */
    1325             : {
    1326             :         php_stream_statbuf  ssb;
    1327        8763 :         if (php_stream_stat((php_stream*)handle, &ssb) == 0) {
    1328        8761 :                 return ssb.sb.st_size;
    1329             :         }
    1330           2 :         return 0;
    1331             : }
    1332             : /* }}} */
    1333             : 
    1334        8523 : static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle) /* {{{ */
    1335             : {
    1336        8523 :         return php_stream_open_for_zend_ex(filename, handle, USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE);
    1337             : }
    1338             : /* }}} */
    1339             : 
    1340        8538 : PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode) /* {{{ */
    1341             : {
    1342             :         char *p;
    1343             :         size_t len, mapped_len;
    1344        8538 :         php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
    1345             : 
    1346        8538 :         if (stream) {
    1347             : #if HAVE_MMAP || defined(PHP_WIN32)
    1348        8477 :                 size_t page_size = REAL_PAGE_SIZE;
    1349             : #endif
    1350             : 
    1351        8477 :                 handle->filename = (char*)filename;
    1352        8477 :                 handle->free_filename = 0;
    1353        8477 :                 handle->handle.stream.handle  = stream;
    1354        8477 :                 handle->handle.stream.reader  = (zend_stream_reader_t)_php_stream_read;
    1355        8477 :                 handle->handle.stream.fsizer  = php_zend_stream_fsizer;
    1356        8477 :                 handle->handle.stream.isatty  = 0;
    1357             :                 /* can we mmap immediately? */
    1358        8477 :                 memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
    1359        8477 :                 len = php_zend_stream_fsizer(stream);
    1360       41791 :                 if (len != 0
    1361             : #if HAVE_MMAP || defined(PHP_WIN32)
    1362        8469 :                 && ((len - 1) % page_size) <= page_size - ZEND_MMAP_AHEAD
    1363             : #endif
    1364       16936 :                 && php_stream_mmap_possible(stream)
    1365        8189 :                 && (p = php_stream_mmap_range(stream, 0, len, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped_len)) != NULL) {
    1366        8189 :                         handle->handle.stream.closer   = php_zend_stream_mmap_closer;
    1367        8189 :                         handle->handle.stream.mmap.buf = p;
    1368        8189 :                         handle->handle.stream.mmap.len = mapped_len;
    1369        8189 :                         handle->type = ZEND_HANDLE_MAPPED;
    1370             :                 } else {
    1371         288 :                         handle->handle.stream.closer = php_zend_stream_closer;
    1372         288 :                         handle->type = ZEND_HANDLE_STREAM;
    1373             :                 }
    1374             :                 /* suppress warning if this stream is not explicitly closed */
    1375        8477 :                 php_stream_auto_cleanup(stream);
    1376             : 
    1377        8477 :                 return SUCCESS;
    1378             :         }
    1379          61 :         return FAILURE;
    1380             : }
    1381             : /* }}} */
    1382             : 
    1383       14917 : static zend_string *php_resolve_path_for_zend(const char *filename, int filename_len) /* {{{ */
    1384             : {
    1385       14917 :         return php_resolve_path(filename, filename_len, PG(include_path));
    1386             : }
    1387             : /* }}} */
    1388             : 
    1389             : /* {{{ php_get_configuration_directive_for_zend
    1390             :  */
    1391     5248789 : static zval *php_get_configuration_directive_for_zend(zend_string *name)
    1392             : {
    1393     5248789 :         return cfg_get_entry_ex(name);
    1394             : }
    1395             : /* }}} */
    1396             : 
    1397             : /* {{{ php_free_request_globals
    1398             :  */
    1399       20911 : static void php_free_request_globals(void)
    1400             : {
    1401       20911 :         if (PG(last_error_message)) {
    1402        5146 :                 free(PG(last_error_message));
    1403        5146 :                 PG(last_error_message) = NULL;
    1404             :         }
    1405       20911 :         if (PG(last_error_file)) {
    1406        5146 :                 free(PG(last_error_file));
    1407        5146 :                 PG(last_error_file) = NULL;
    1408             :         }
    1409       20911 :         if (PG(php_sys_temp_dir)) {
    1410         510 :                 efree(PG(php_sys_temp_dir));
    1411         510 :                 PG(php_sys_temp_dir) = NULL;
    1412             :         }
    1413       20911 : }
    1414             : /* }}} */
    1415             : 
    1416             : /* {{{ php_message_handler_for_zend
    1417             :  */
    1418          34 : static void php_message_handler_for_zend(zend_long message, const void *data)
    1419             : {
    1420          34 :         switch (message) {
    1421             :                 case ZMSG_FAILED_INCLUDE_FOPEN:
    1422          29 :                         php_error_docref("function.include", E_WARNING, "Failed opening '%s' for inclusion (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
    1423          29 :                         break;
    1424             :                 case ZMSG_FAILED_REQUIRE_FOPEN:
    1425           3 :                         php_error_docref("function.require", E_COMPILE_ERROR, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
    1426           0 :                         break;
    1427             :                 case ZMSG_FAILED_HIGHLIGHT_FOPEN:
    1428           2 :                         php_error_docref(NULL, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
    1429           2 :                         break;
    1430             :                 case ZMSG_MEMORY_LEAK_DETECTED:
    1431             :                 case ZMSG_MEMORY_LEAK_REPEATED:
    1432             : #if ZEND_DEBUG
    1433             :                         if (EG(error_reporting) & E_WARNING) {
    1434             :                                 char memory_leak_buf[1024];
    1435             : 
    1436             :                                 if (message==ZMSG_MEMORY_LEAK_DETECTED) {
    1437             :                                         zend_leak_info *t = (zend_leak_info *) data;
    1438             : 
    1439             :                                         snprintf(memory_leak_buf, 512, "%s(%d) :  Freeing 0x%.8lX (%zu bytes), script=%s\n", t->filename, t->lineno, (zend_uintptr_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
    1440             :                                         if (t->orig_filename) {
    1441             :                                                 char relay_buf[512];
    1442             : 
    1443             :                                                 snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
    1444             :                                                 strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf));
    1445             :                                         }
    1446             :                                 } else {
    1447             :                                         unsigned long leak_count = (zend_uintptr_t) data;
    1448             : 
    1449             :                                         snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":""));
    1450             :                                 }
    1451             : #       if defined(PHP_WIN32)
    1452             :                                 OutputDebugString(memory_leak_buf);
    1453             : #       else
    1454             :                                 fprintf(stderr, "%s", memory_leak_buf);
    1455             : #       endif
    1456             :                         }
    1457             : #endif
    1458           0 :                         break;
    1459             :                 case ZMSG_MEMORY_LEAKS_GRAND_TOTAL:
    1460             : #if ZEND_DEBUG
    1461             :                         if (EG(error_reporting) & E_WARNING) {
    1462             :                                 char memory_leak_buf[512];
    1463             : 
    1464             :                                 snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((uint32_t *) data));
    1465             : #       if defined(PHP_WIN32)
    1466             :                                 OutputDebugString(memory_leak_buf);
    1467             : #       else
    1468             :                                 fprintf(stderr, "%s", memory_leak_buf);
    1469             : #       endif
    1470             :                         }
    1471             : #endif
    1472           0 :                         break;
    1473             :                 case ZMSG_LOG_SCRIPT_NAME: {
    1474             :                                 struct tm *ta, tmbuf;
    1475             :                                 time_t curtime;
    1476             :                                 char *datetime_str, asctimebuf[52];
    1477             :                                 char memory_leak_buf[4096];
    1478             : 
    1479           0 :                                 time(&curtime);
    1480           0 :                                 ta = php_localtime_r(&curtime, &tmbuf);
    1481           0 :                                 datetime_str = php_asctime_r(ta, asctimebuf);
    1482           0 :                                 if (datetime_str) {
    1483           0 :                                         datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
    1484           0 :                                         snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s]  Script:  '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
    1485             :                                 } else {
    1486           0 :                                         snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null]  Script:  '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
    1487             :                                 }
    1488             : #       if defined(PHP_WIN32)
    1489             :                                 OutputDebugString(memory_leak_buf);
    1490             : #       else
    1491           0 :                                 fprintf(stderr, "%s", memory_leak_buf);
    1492             : #       endif
    1493             :                         }
    1494             :                         break;
    1495             :         }
    1496          31 : }
    1497             : /* }}} */
    1498             : 
    1499             : 
    1500          13 : void php_on_timeout(int seconds)
    1501             : {
    1502          13 :         PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
    1503          13 :         zend_set_timeout(EG(timeout_seconds), 1);
    1504          13 :         if(PG(exit_on_timeout)) sapi_terminate_process();
    1505          13 : }
    1506             : 
    1507             : #if PHP_SIGCHILD
    1508             : /* {{{ sigchld_handler
    1509             :  */
    1510             : static void sigchld_handler(int apar)
    1511             : {
    1512             :         int errno_save = errno;
    1513             : 
    1514             :         while (waitpid(-1, NULL, WNOHANG) > 0);
    1515             :         signal(SIGCHLD, sigchld_handler);
    1516             : 
    1517             :         errno = errno_save;
    1518             : }
    1519             : /* }}} */
    1520             : #endif
    1521             : 
    1522             : /* {{{ php_start_sapi()
    1523             :  */
    1524           0 : static int php_start_sapi(void)
    1525             : {
    1526           0 :         int retval = SUCCESS;
    1527             : 
    1528           0 :         if(!SG(sapi_started)) {
    1529           0 :                 zend_try {
    1530           0 :                         PG(during_request_startup) = 1;
    1531             : 
    1532             :                         /* initialize global variables */
    1533           0 :                         PG(modules_activated) = 0;
    1534           0 :                         PG(header_is_being_sent) = 0;
    1535           0 :                         PG(connection_status) = PHP_CONNECTION_NORMAL;
    1536             : 
    1537           0 :                         zend_activate();
    1538           0 :                         zend_set_timeout(EG(timeout_seconds), 1);
    1539           0 :                         zend_activate_modules();
    1540           0 :                         PG(modules_activated)=1;
    1541           0 :                 } zend_catch {
    1542           0 :                         retval = FAILURE;
    1543           0 :                 } zend_end_try();
    1544             : 
    1545           0 :                 SG(sapi_started) = 1;
    1546             :         }
    1547           0 :         return retval;
    1548             : }
    1549             : 
    1550             : /* }}} */
    1551             : 
    1552             : /* {{{ php_request_startup
    1553             :  */
    1554             : #ifndef APACHE_HOOKS
    1555       20873 : int php_request_startup(void)
    1556             : {
    1557       20873 :         int retval = SUCCESS;
    1558             : 
    1559             : #ifdef HAVE_DTRACE
    1560             :         DTRACE_REQUEST_STARTUP(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), (char *)SAFE_FILENAME(SG(request_info).request_method));
    1561             : #endif /* HAVE_DTRACE */
    1562             : 
    1563             : #ifdef PHP_WIN32
    1564             :         PG(com_initialized) = 0;
    1565             : #endif
    1566             : 
    1567             : #if PHP_SIGCHILD
    1568             :         signal(SIGCHLD, sigchld_handler);
    1569             : #endif
    1570             : 
    1571       20873 :         zend_try {
    1572       20873 :                 PG(in_error_log) = 0;
    1573       20873 :                 PG(during_request_startup) = 1;
    1574             : 
    1575       20873 :                 php_output_activate();
    1576             : 
    1577             :                 /* initialize global variables */
    1578       20873 :                 PG(modules_activated) = 0;
    1579       20873 :                 PG(header_is_being_sent) = 0;
    1580       20873 :                 PG(connection_status) = PHP_CONNECTION_NORMAL;
    1581       20873 :                 PG(in_user_include) = 0;
    1582             : 
    1583       20873 :                 zend_activate();
    1584       20873 :                 sapi_activate();
    1585             : 
    1586             : #ifdef ZEND_SIGNALS
    1587             :                 zend_signal_activate();
    1588             : #endif
    1589             : 
    1590       20873 :                 if (PG(max_input_time) == -1) {
    1591       20873 :                         zend_set_timeout(EG(timeout_seconds), 1);
    1592             :                 } else {
    1593           0 :                         zend_set_timeout(PG(max_input_time), 1);
    1594             :                 }
    1595             : 
    1596             :                 /* Disable realpath cache if an open_basedir is set */
    1597       20873 :                 if (PG(open_basedir) && *PG(open_basedir)) {
    1598          76 :                         CWDG(realpath_cache_size_limit) = 0;
    1599             :                 }
    1600             : 
    1601       20873 :                 if (PG(expose_php)) {
    1602       20870 :                         sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
    1603             :                 }
    1604             : 
    1605       20880 :                 if (PG(output_handler) && PG(output_handler)[0]) {
    1606             :                         zval oh;
    1607             : 
    1608          14 :                         ZVAL_STRING(&oh, PG(output_handler));
    1609           7 :                         php_output_start_user(&oh, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
    1610           7 :                         zval_ptr_dtor(&oh);
    1611       20866 :                 } else if (PG(output_buffering)) {
    1612           1 :                         php_output_start_user(NULL, PG(output_buffering) > 1 ? PG(output_buffering) : 0, PHP_OUTPUT_HANDLER_STDFLAGS);
    1613       20865 :                 } else if (PG(implicit_flush)) {
    1614       20461 :                         php_output_set_implicit_flush(1);
    1615             :                 }
    1616             : 
    1617             :                 /* We turn this off in php_execute_script() */
    1618             :                 /* PG(during_request_startup) = 0; */
    1619             : 
    1620       20873 :                 php_hash_environment();
    1621       20873 :                 zend_activate_modules();
    1622       20873 :                 PG(modules_activated)=1;
    1623           0 :         } zend_catch {
    1624           0 :                 retval = FAILURE;
    1625       20873 :         } zend_end_try();
    1626             : 
    1627       20873 :         SG(sapi_started) = 1;
    1628             : 
    1629       20873 :         return retval;
    1630             : }
    1631             : # else
    1632             : int php_request_startup(void)
    1633             : {
    1634             :         int retval = SUCCESS;
    1635             : 
    1636             : #if PHP_SIGCHILD
    1637             :         signal(SIGCHLD, sigchld_handler);
    1638             : #endif
    1639             : 
    1640             :         if (php_start_sapi() == FAILURE) {
    1641             :                 return FAILURE;
    1642             :         }
    1643             : 
    1644             :         php_output_activate();
    1645             :         sapi_activate();
    1646             :         php_hash_environment();
    1647             : 
    1648             :         zend_try {
    1649             :                 PG(during_request_startup) = 1;
    1650             :                 if (PG(expose_php)) {
    1651             :                         sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
    1652             :                 }
    1653             :         } zend_catch {
    1654             :                 retval = FAILURE;
    1655             :         } zend_end_try();
    1656             : 
    1657             :         return retval;
    1658             : }
    1659             : # endif
    1660             : /* }}} */
    1661             : 
    1662             : /* {{{ php_request_startup_for_hook
    1663             :  */
    1664           0 : int php_request_startup_for_hook(void)
    1665             : {
    1666           0 :         int retval = SUCCESS;
    1667             : 
    1668             : #if PHP_SIGCHLD
    1669             :         signal(SIGCHLD, sigchld_handler);
    1670             : #endif
    1671             : 
    1672           0 :         if (php_start_sapi() == FAILURE) {
    1673           0 :                 return FAILURE;
    1674             :         }
    1675             : 
    1676           0 :         php_output_activate();
    1677           0 :         sapi_activate_headers_only();
    1678           0 :         php_hash_environment();
    1679             : 
    1680           0 :         return retval;
    1681             : }
    1682             : /* }}} */
    1683             : 
    1684             : /* {{{ php_request_shutdown_for_exec
    1685             :  */
    1686           0 : void php_request_shutdown_for_exec(void *dummy)
    1687             : {
    1688             : 
    1689             :         /* used to close fd's in the 3..255 range here, but it's problematic
    1690             :          */
    1691           0 :         shutdown_memory_manager(1, 1);
    1692           0 :         zend_interned_strings_restore();
    1693           0 : }
    1694             : /* }}} */
    1695             : 
    1696             : /* {{{ php_request_shutdown_for_hook
    1697             :  */
    1698           0 : void php_request_shutdown_for_hook(void *dummy)
    1699             : {
    1700             : 
    1701           0 :         if (PG(modules_activated)) zend_try {
    1702           0 :                 php_call_shutdown_functions();
    1703           0 :         } zend_end_try();
    1704             : 
    1705           0 :         if (PG(modules_activated)) {
    1706           0 :                 zend_deactivate_modules();
    1707           0 :                 php_free_shutdown_functions();
    1708             :         }
    1709             : 
    1710           0 :         zend_try {
    1711           0 :                 zend_unset_timeout();
    1712           0 :         } zend_end_try();
    1713             : 
    1714           0 :         zend_try {
    1715             :                 int i;
    1716             : 
    1717           0 :                 for (i = 0; i < NUM_TRACK_VARS; i++) {
    1718           0 :                         zval_ptr_dtor(&PG(http_globals)[i]);
    1719             :                 }
    1720           0 :         } zend_end_try();
    1721             : 
    1722           0 :         zend_deactivate();
    1723             : 
    1724           0 :         zend_try {
    1725           0 :                 sapi_deactivate();
    1726           0 :         } zend_end_try();
    1727             : 
    1728           0 :         zend_try {
    1729           0 :                 php_shutdown_stream_hashes();
    1730           0 :         } zend_end_try();
    1731             : 
    1732           0 :         zend_try {
    1733           0 :                 shutdown_memory_manager(CG(unclean_shutdown), 0);
    1734           0 :         } zend_end_try();
    1735             : 
    1736           0 :         zend_interned_strings_restore();
    1737             : 
    1738             : #ifdef ZEND_SIGNALS
    1739             :         zend_try {
    1740             :                 zend_signal_deactivate();
    1741             :         } zend_end_try();
    1742             : #endif
    1743           0 : }
    1744             : 
    1745             : /* }}} */
    1746             : 
    1747             : /* {{{ php_request_shutdown
    1748             :  */
    1749       20911 : void php_request_shutdown(void *dummy)
    1750             : {
    1751             :         zend_bool report_memleaks;
    1752             : 
    1753       20911 :         report_memleaks = PG(report_memleaks);
    1754             : 
    1755             :         /* EG(current_execute_data) points into nirvana and therefore cannot be safely accessed
    1756             :          * inside zend_executor callback functions.
    1757             :          */
    1758       20911 :         EG(current_execute_data) = NULL;
    1759             : 
    1760       20911 :         php_deactivate_ticks();
    1761             : 
    1762             :         /* 1. Call all possible shutdown functions registered with register_shutdown_function() */
    1763       20911 :         if (PG(modules_activated)) zend_try {
    1764       20911 :                 php_call_shutdown_functions();
    1765       20911 :         } zend_end_try();
    1766             : 
    1767             :         /* 2. Call all possible __destruct() functions */
    1768       20911 :         zend_try {
    1769       20911 :                 zend_call_destructors();
    1770       20911 :         } zend_end_try();
    1771             : 
    1772             :         /* 3. Flush all output buffers */
    1773       20911 :         zend_try {
    1774       20911 :                 zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;
    1775             : 
    1776       21463 :                 if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
    1777         552 :                         (size_t)PG(memory_limit) < zend_memory_usage(1)
    1778             :                 ) {
    1779           0 :                         send_buffer = 0;
    1780             :                 }
    1781             : 
    1782       20911 :                 if (!send_buffer) {
    1783           0 :                         php_output_discard_all();
    1784             :                 } else {
    1785       20911 :                         php_output_end_all();
    1786             :                 }
    1787       20911 :         } zend_end_try();
    1788             : 
    1789             :         /* 4. Reset max_execution_time (no longer executing php code after response sent) */
    1790       20911 :         zend_try {
    1791       20911 :                 zend_unset_timeout();
    1792       20911 :         } zend_end_try();
    1793             : 
    1794             :         /* 5. Call all extensions RSHUTDOWN functions */
    1795       20911 :         if (PG(modules_activated)) {
    1796       20911 :                 zend_deactivate_modules();
    1797       20911 :                 php_free_shutdown_functions();
    1798             :         }
    1799             : 
    1800             :         /* 6. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */
    1801       20911 :         zend_try {
    1802       20911 :                 php_output_deactivate();
    1803       20911 :         } zend_end_try();
    1804             : 
    1805             :         /* 7. Destroy super-globals */
    1806       20911 :         zend_try {
    1807             :                 int i;
    1808             : 
    1809      146377 :                 for (i=0; i<NUM_TRACK_VARS; i++) {
    1810      125466 :                         zval_ptr_dtor(&PG(http_globals)[i]);
    1811             :                 }
    1812       20911 :         } zend_end_try();
    1813             : 
    1814             :         /* 8. free request-bound globals */
    1815       20911 :         php_free_request_globals();
    1816             : 
    1817             :         /* 9. Shutdown scanner/executor/compiler and restore ini entries */
    1818       20911 :         zend_deactivate();
    1819             : 
    1820             :         /* 10. Call all extensions post-RSHUTDOWN functions */
    1821       20911 :         zend_try {
    1822       20911 :                 zend_post_deactivate_modules();
    1823       20911 :         } zend_end_try();
    1824             : 
    1825             :         /* 11. SAPI related shutdown (free stuff) */
    1826       20911 :         zend_try {
    1827       20911 :                 sapi_deactivate();
    1828       20911 :         } zend_end_try();
    1829             : 
    1830             :         /* 12. free virtual CWD memory */
    1831       20911 :         virtual_cwd_deactivate();
    1832             : 
    1833             :         /* 13. Destroy stream hashes */
    1834       20911 :         zend_try {
    1835       20911 :                 php_shutdown_stream_hashes();
    1836       20911 :         } zend_end_try();
    1837             : 
    1838             :         /* 14. Free Willy (here be crashes) */
    1839       20911 :         zend_interned_strings_restore();
    1840       20911 :         zend_try {
    1841       20911 :                 shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0);
    1842       20911 :         } zend_end_try();
    1843             : 
    1844             :         /* 15. Reset max_execution_time */
    1845       20911 :         zend_try {
    1846       20911 :                 zend_unset_timeout();
    1847       20911 :         } zend_end_try();
    1848             : 
    1849             : #ifdef PHP_WIN32
    1850             :         if (PG(com_initialized)) {
    1851             :                 CoUninitialize();
    1852             :                 PG(com_initialized) = 0;
    1853             :         }
    1854             : #endif
    1855             : 
    1856             : #ifdef HAVE_DTRACE
    1857             :         DTRACE_REQUEST_SHUTDOWN(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), (char *)SAFE_FILENAME(SG(request_info).request_method));
    1858             : #endif /* HAVE_DTRACE */
    1859       20911 : }
    1860             : /* }}} */
    1861             : 
    1862             : /* {{{ php_com_initialize
    1863             :  */
    1864           0 : PHPAPI void php_com_initialize(void)
    1865             : {
    1866             : #ifdef PHP_WIN32
    1867             :         if (!PG(com_initialized)) {
    1868             :                 if (CoInitialize(NULL) == S_OK) {
    1869             :                         PG(com_initialized) = 1;
    1870             :                 }
    1871             :         }
    1872             : #endif
    1873           0 : }
    1874             : /* }}} */
    1875             : 
    1876             : /* {{{ php_output_wrapper
    1877             :  */
    1878      335381 : static size_t php_output_wrapper(const char *str, size_t str_length)
    1879             : {
    1880      335381 :         return php_output_write(str, str_length);
    1881             : }
    1882             : /* }}} */
    1883             : 
    1884             : #ifdef ZTS
    1885             : /* {{{ core_globals_ctor
    1886             :  */
    1887             : static void core_globals_ctor(php_core_globals *core_globals)
    1888             : {
    1889             :         memset(core_globals, 0, sizeof(*core_globals));
    1890             : }
    1891             : /* }}} */
    1892             : #endif
    1893             : 
    1894             : /* {{{ core_globals_dtor
    1895             :  */
    1896       20952 : static void core_globals_dtor(php_core_globals *core_globals)
    1897             : {
    1898       20952 :         if (core_globals->last_error_message) {
    1899           4 :                 free(core_globals->last_error_message);
    1900             :         }
    1901       20952 :         if (core_globals->last_error_file) {
    1902           4 :                 free(core_globals->last_error_file);
    1903             :         }
    1904       20952 :         if (core_globals->disable_functions) {
    1905           4 :                 free(core_globals->disable_functions);
    1906             :         }
    1907       20952 :         if (core_globals->disable_classes) {
    1908           1 :                 free(core_globals->disable_classes);
    1909             :         }
    1910       20952 :         if (core_globals->php_binary) {
    1911       20952 :                 free(core_globals->php_binary);
    1912             :         }
    1913             : 
    1914       20952 :         php_shutdown_ticks();
    1915       20952 : }
    1916             : /* }}} */
    1917             : 
    1918         142 : PHP_MINFO_FUNCTION(php_core) { /* {{{ */
    1919         142 :         php_info_print_table_start();
    1920         142 :         php_info_print_table_row(2, "PHP Version", PHP_VERSION);
    1921         142 :         php_info_print_table_end();
    1922         142 :         DISPLAY_INI_ENTRIES();
    1923         142 : }
    1924             : /* }}} */
    1925             : 
    1926             : /* {{{ php_register_extensions
    1927             :  */
    1928       20916 : int php_register_extensions(zend_module_entry **ptr, int count)
    1929             : {
    1930       20916 :         zend_module_entry **end = ptr + count;
    1931             : 
    1932     1422288 :         while (ptr < end) {
    1933     1380456 :                 if (*ptr) {
    1934     1380456 :                         if (zend_register_internal_module(*ptr)==NULL) {
    1935           0 :                                 return FAILURE;
    1936             :                         }
    1937             :                 }
    1938     1380456 :                 ptr++;
    1939             :         }
    1940       20916 :         return SUCCESS;
    1941             : }
    1942             : 
    1943             : /* A very long time ago php_module_startup() was refactored in a way
    1944             :  * which broke calling it with more than one additional module.
    1945             :  * This alternative to php_register_extensions() works around that
    1946             :  * by walking the shallower structure.
    1947             :  *
    1948             :  * See algo: https://bugs.php.net/bug.php?id=63159
    1949             :  */
    1950       20916 : static int php_register_extensions_bc(zend_module_entry *ptr, int count)
    1951             : {
    1952       42238 :         while (count--) {
    1953         406 :                 if (zend_register_internal_module(ptr++) == NULL) {
    1954           0 :                         return FAILURE;
    1955             :                 }
    1956             :         }
    1957       20916 :         return SUCCESS;
    1958             : }
    1959             : /* }}} */
    1960             : 
    1961             : #ifdef PHP_WIN32
    1962             : static _invalid_parameter_handler old_invalid_parameter_handler;
    1963             : 
    1964             : void dummy_invalid_parameter_handler(
    1965             :                 const wchar_t *expression,
    1966             :                 const wchar_t *function,
    1967             :                 const wchar_t *file,
    1968             :                 unsigned int   line,
    1969             :                 uintptr_t      pEwserved)
    1970             : {
    1971             :         static int called = 0;
    1972             :         char buf[1024];
    1973             :         int len;
    1974             : 
    1975             :         if (!called) {
    1976             :                         if(PG(windows_show_crt_warning)) {
    1977             :                         called = 1;
    1978             :                         if (function) {
    1979             :                                 if (file) {
    1980             :                                         len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%u)", function, file, line);
    1981             :                                 } else {
    1982             :                                         len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function);
    1983             :                                 }
    1984             :                         } else {
    1985             :                                 len = _snprintf(buf, sizeof(buf)-1, "Invalid CRT parameter detected (function not known)");
    1986             :                         }
    1987             :                         zend_error(E_WARNING, "%s", buf);
    1988             :                         called = 0;
    1989             :                 }
    1990             :         }
    1991             : }
    1992             : #endif
    1993             : 
    1994             : /* {{{ php_module_startup
    1995             :  */
    1996       20916 : int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
    1997             : {
    1998             :         zend_utility_functions zuf;
    1999             :         zend_utility_values zuv;
    2000       20916 :         int retval = SUCCESS, module_number=0;  /* for REGISTER_INI_ENTRIES() */
    2001             :         char *php_os;
    2002             :         zend_module_entry *module;
    2003             : 
    2004             : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
    2005             :         WORD wVersionRequested = MAKEWORD(2, 0);
    2006             :         WSADATA wsaData;
    2007             : #endif
    2008             : #ifdef PHP_WIN32
    2009             :         php_os = "WINNT";
    2010             : 
    2011             :         old_invalid_parameter_handler =
    2012             :                 _set_invalid_parameter_handler(dummy_invalid_parameter_handler);
    2013             :         if (old_invalid_parameter_handler != NULL) {
    2014             :                 _set_invalid_parameter_handler(old_invalid_parameter_handler);
    2015             :         }
    2016             : 
    2017             :         /* Disable the message box for assertions.*/
    2018             :         _CrtSetReportMode(_CRT_ASSERT, 0);
    2019             : #else
    2020       20916 :         php_os = PHP_OS;
    2021             : #endif
    2022             : 
    2023             : #ifdef ZTS
    2024             :         (void)ts_resource(0);
    2025             : #endif
    2026             : 
    2027             : #ifdef PHP_WIN32
    2028             :         php_win32_init_rng_lock();
    2029             : #endif
    2030             : 
    2031       20916 :         module_shutdown = 0;
    2032       20916 :         module_startup = 1;
    2033       20916 :         sapi_initialize_empty_request();
    2034       20916 :         sapi_activate();
    2035             : 
    2036       20916 :         if (module_initialized) {
    2037           0 :                 return SUCCESS;
    2038             :         }
    2039             : 
    2040       20916 :         sapi_module = *sf;
    2041             : 
    2042       20916 :         php_output_startup();
    2043             : 
    2044             : #ifdef ZTS
    2045             :         ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
    2046             :         php_startup_ticks();
    2047             : #ifdef PHP_WIN32
    2048             :         ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
    2049             : #endif
    2050             : #else
    2051       20916 :         php_startup_ticks();
    2052             : #endif
    2053       20916 :         gc_globals_ctor();
    2054             : 
    2055       20916 :         zuf.error_function = php_error_cb;
    2056       20916 :         zuf.printf_function = php_printf;
    2057       20916 :         zuf.write_function = php_output_wrapper;
    2058       20916 :         zuf.fopen_function = php_fopen_wrapper_for_zend;
    2059       20916 :         zuf.message_handler = php_message_handler_for_zend;
    2060       20916 :         zuf.block_interruptions = sapi_module.block_interruptions;
    2061       20916 :         zuf.unblock_interruptions = sapi_module.unblock_interruptions;
    2062       20916 :         zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
    2063       20916 :         zuf.ticks_function = php_run_ticks;
    2064       20916 :         zuf.on_timeout = php_on_timeout;
    2065       20916 :         zuf.stream_open_function = php_stream_open_for_zend;
    2066       20916 :         zuf.vspprintf_function = vspprintf;
    2067       20916 :         zuf.vstrpprintf_function = vstrpprintf;
    2068       20916 :         zuf.getenv_function = sapi_getenv;
    2069       20916 :         zuf.resolve_path_function = php_resolve_path_for_zend;
    2070       20916 :         zend_startup(&zuf, NULL);
    2071             : 
    2072             : #if HAVE_SETLOCALE
    2073       20916 :         setlocale(LC_CTYPE, "");
    2074             :         zend_update_current_locale();
    2075             : #endif
    2076             : 
    2077             : #if HAVE_TZSET
    2078       20916 :         tzset();
    2079             : #endif
    2080             : 
    2081             : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
    2082             :         /* start up winsock services */
    2083             :         if (WSAStartup(wVersionRequested, &wsaData) != 0) {
    2084             :                 php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
    2085             :                 return FAILURE;
    2086             :         }
    2087             : #endif
    2088             : 
    2089       20916 :         le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
    2090             : 
    2091             :         /* Register constants */
    2092       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
    2093       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_MAJOR_VERSION", PHP_MAJOR_VERSION, CONST_PERSISTENT | CONST_CS);
    2094       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_MINOR_VERSION", PHP_MINOR_VERSION, CONST_PERSISTENT | CONST_CS);
    2095       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_RELEASE_VERSION", PHP_RELEASE_VERSION, CONST_PERSISTENT | CONST_CS);
    2096       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTRA_VERSION", PHP_EXTRA_VERSION, sizeof(PHP_EXTRA_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
    2097       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_VERSION_ID", PHP_VERSION_ID, CONST_PERSISTENT | CONST_CS);
    2098             : #ifdef ZTS
    2099             :         REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 1, CONST_PERSISTENT | CONST_CS);
    2100             : #else
    2101       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 0, CONST_PERSISTENT | CONST_CS);
    2102             : #endif
    2103       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS);
    2104       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
    2105       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS);
    2106       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
    2107       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS);
    2108       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
    2109       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
    2110       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
    2111       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
    2112             : #ifndef PHP_WIN32
    2113       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_MANDIR", PHP_MANDIR, sizeof(PHP_MANDIR)-1, CONST_PERSISTENT | CONST_CS);
    2114             : #endif
    2115       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
    2116       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
    2117       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
    2118       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
    2119       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS);
    2120       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR, sizeof(PHP_CONFIG_FILE_SCAN_DIR)-1, CONST_PERSISTENT | CONST_CS);
    2121       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
    2122       20916 :         REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
    2123       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS);
    2124       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", ZEND_LONG_MAX, CONST_PERSISTENT | CONST_CS);
    2125       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MIN", ZEND_LONG_MIN, CONST_PERSISTENT | CONST_CS);
    2126       20916 :         REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", SIZEOF_ZEND_LONG, CONST_PERSISTENT | CONST_CS);
    2127             : 
    2128             : #ifdef PHP_WIN32
    2129             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR",      EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
    2130             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MINOR",      EG(windows_version_info).dwMinorVersion, CONST_PERSISTENT | CONST_CS);
    2131             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_BUILD",      EG(windows_version_info).dwBuildNumber, CONST_PERSISTENT | CONST_CS);
    2132             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PLATFORM",   EG(windows_version_info).dwPlatformId, CONST_PERSISTENT | CONST_CS);
    2133             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MAJOR",   EG(windows_version_info).wServicePackMajor, CONST_PERSISTENT | CONST_CS);
    2134             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MINOR",   EG(windows_version_info).wServicePackMinor, CONST_PERSISTENT | CONST_CS);
    2135             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SUITEMASK",  EG(windows_version_info).wSuiteMask, CONST_PERSISTENT | CONST_CS);
    2136             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PRODUCTTYPE", EG(windows_version_info).wProductType, CONST_PERSISTENT | CONST_CS);
    2137             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_DOMAIN_CONTROLLER", VER_NT_DOMAIN_CONTROLLER, CONST_PERSISTENT | CONST_CS);
    2138             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_SERVER", VER_NT_SERVER, CONST_PERSISTENT | CONST_CS);
    2139             :         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);
    2140             : #endif
    2141             : 
    2142       20916 :         php_binary_init();
    2143       20916 :         if (PG(php_binary)) {
    2144       20916 :                 REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS);
    2145             :         } else {
    2146           0 :                 REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS);
    2147             :         }
    2148             : 
    2149       20916 :         php_output_register_constants();
    2150       20916 :         php_rfc1867_register_constants();
    2151             : 
    2152             :         /* this will read in php.ini, set up the configuration parameters,
    2153             :            load zend extensions and register php function extensions
    2154             :            to be loaded later */
    2155       20916 :         if (php_init_config() == FAILURE) {
    2156           0 :                 return FAILURE;
    2157             :         }
    2158             : 
    2159             :         /* Register PHP core ini entries */
    2160       20916 :         REGISTER_INI_ENTRIES();
    2161             : 
    2162             :         /* Register Zend ini entries */
    2163       20916 :         zend_register_standard_ini_entries();
    2164             : 
    2165             :         /* Disable realpath cache if an open_basedir is set */
    2166       20916 :         if (PG(open_basedir) && *PG(open_basedir)) {
    2167          76 :                 CWDG(realpath_cache_size_limit) = 0;
    2168             :         }
    2169             : 
    2170             :         /* initialize stream wrappers registry
    2171             :          * (this uses configuration parameters from php.ini)
    2172             :          */
    2173       20916 :         if (php_init_stream_wrappers(module_number) == FAILURE) {
    2174           0 :                 php_printf("PHP:  Unable to initialize stream url wrappers.\n");
    2175           0 :                 return FAILURE;
    2176             :         }
    2177             : 
    2178       20916 :         zuv.html_errors = 1;
    2179       20916 :         zuv.import_use_extension = ".php";
    2180       20916 :         zuv.import_use_extension_length = (uint)strlen(zuv.import_use_extension);
    2181       20916 :         php_startup_auto_globals();
    2182       20916 :         zend_set_utility_values(&zuv);
    2183       20916 :         php_startup_sapi_content_types();
    2184             : 
    2185             :         /* startup extensions statically compiled in */
    2186       20916 :         if (php_register_internal_extensions_func() == FAILURE) {
    2187           0 :                 php_printf("Unable to start builtin modules\n");
    2188           0 :                 return FAILURE;
    2189             :         }
    2190             : 
    2191             :         /* start additional PHP extensions */
    2192       20916 :         php_register_extensions_bc(additional_modules, num_additional_modules);
    2193             : 
    2194             :         /* load and startup extensions compiled as shared objects (aka DLLs)
    2195             :            as requested by php.ini entries
    2196             :            these are loaded after initialization of internal extensions
    2197             :            as extensions *might* rely on things from ext/standard
    2198             :            which is always an internal extension and to be initialized
    2199             :            ahead of all other internals
    2200             :          */
    2201       20916 :         php_ini_register_extensions();
    2202       20916 :         zend_startup_modules();
    2203             : 
    2204             :         /* start Zend extensions */
    2205       20916 :         zend_startup_extensions();
    2206             : 
    2207       20916 :         zend_collect_module_handlers();
    2208             : 
    2209             :         /* register additional functions */
    2210       20916 :         if (sapi_module.additional_functions) {
    2211       20701 :                 if ((module = zend_hash_str_find_ptr(&module_registry, "standard", sizeof("standard")-1)) != NULL) {
    2212       20701 :                         EG(current_module) = module;
    2213       20701 :                         zend_register_functions(NULL, sapi_module.additional_functions, NULL, MODULE_PERSISTENT);
    2214       20701 :                         EG(current_module) = NULL;
    2215             :                 }
    2216             :         }
    2217             : 
    2218             :         /* disable certain classes and functions as requested by php.ini */
    2219       20916 :         php_disable_functions();
    2220       20916 :         php_disable_classes();
    2221             : 
    2222             :         /* make core report what it should */
    2223       20916 :         if ((module = zend_hash_str_find_ptr(&module_registry, "core", sizeof("core")-1)) != NULL) {
    2224       20916 :                 module->version = PHP_VERSION;
    2225       20916 :                 module->info_func = PHP_MINFO(php_core);
    2226             :         }
    2227             : 
    2228       20916 :         zend_post_startup();
    2229             : 
    2230       20916 :         module_initialized = 1;
    2231             : 
    2232             :         /* Check for deprecated directives */
    2233             :         /* NOTE: If you add anything here, remember to add it to Makefile.global! */
    2234             :         {
    2235             :                 struct {
    2236             :                         const long error_level;
    2237             :                         const char *phrase;
    2238             :                         const char *directives[17]; /* Remember to change this if the number of directives change */
    2239             :                 } directives[2] = {
    2240             :                         {
    2241             :                                 E_DEPRECATED,
    2242             :                                 "Directive '%s' is deprecated in PHP 5.3 and greater",
    2243             :                                 {
    2244             :                                         NULL
    2245             :                                 }
    2246             :                         },
    2247             :                         {
    2248             :                                 E_CORE_ERROR,
    2249             :                                 "Directive '%s' is no longer available in PHP",
    2250             :                                 {
    2251             :                                         "allow_call_time_pass_reference",
    2252             :                                         "asp_tags",
    2253             :                                         "define_syslog_variables",
    2254             :                                         "highlight.bg",
    2255             :                                         "magic_quotes_gpc",
    2256             :                                         "magic_quotes_runtime",
    2257             :                                         "magic_quotes_sybase",
    2258             :                                         "register_globals",
    2259             :                                         "register_long_arrays",
    2260             :                                         "safe_mode",
    2261             :                                         "safe_mode_gid",
    2262             :                                         "safe_mode_include_dir",
    2263             :                                         "safe_mode_exec_dir",
    2264             :                                         "safe_mode_allowed_env_vars",
    2265             :                                         "safe_mode_protected_env_vars",
    2266             :                                         "zend.ze1_compatibility_mode",
    2267             :                                         NULL
    2268             :                                 }
    2269             :                         }
    2270       20916 :                 };
    2271             : 
    2272             :                 unsigned int i;
    2273             : 
    2274       20916 :                 zend_try {
    2275             :                         /* 2 = Count of deprecation structs */
    2276       62746 :                         for (i = 0; i < 2; i++) {
    2277       41832 :                                 const char **p = directives[i].directives;
    2278             : 
    2279      418296 :                                 while(*p) {
    2280             :                                         zend_long value;
    2281             : 
    2282      334634 :                                         if (cfg_get_long((char*)*p, &value) == SUCCESS && value) {
    2283           2 :                                                 zend_error(directives[i].error_level, directives[i].phrase, *p);
    2284             :                                         }
    2285             : 
    2286      334632 :                                         ++p;
    2287             :                                 }
    2288             :                         }
    2289           2 :                 } zend_catch {
    2290           2 :                         retval = FAILURE;
    2291       20916 :                 } zend_end_try();
    2292             :         }
    2293             : 
    2294       20916 :         sapi_deactivate();
    2295       20916 :         module_startup = 0;
    2296             : 
    2297       20916 :         shutdown_memory_manager(1, 0);
    2298       20916 :         zend_interned_strings_snapshot();
    2299       20916 :         virtual_cwd_activate();
    2300             : 
    2301             :         /* we're done */
    2302       20916 :         return retval;
    2303             : }
    2304             : /* }}} */
    2305             : 
    2306           0 : void php_module_shutdown_for_exec(void)
    2307             : {
    2308             :         /* used to close fd's in the range 3.255 here, but it's problematic */
    2309           0 : }
    2310             : 
    2311             : /* {{{ php_module_shutdown_wrapper
    2312             :  */
    2313           0 : int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
    2314             : {
    2315           0 :         php_module_shutdown();
    2316           0 :         return SUCCESS;
    2317             : }
    2318             : /* }}} */
    2319             : 
    2320             : /* {{{ php_module_shutdown
    2321             :  */
    2322       20952 : void php_module_shutdown(void)
    2323             : {
    2324       20952 :         int module_number=0;    /* for UNREGISTER_INI_ENTRIES() */
    2325             : 
    2326       20952 :         module_shutdown = 1;
    2327             : 
    2328       20952 :         if (!module_initialized) {
    2329           0 :                 return;
    2330             :         }
    2331             : 
    2332             : #ifdef ZTS
    2333             :         ts_free_worker_threads();
    2334             : #endif
    2335             : 
    2336             : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
    2337             :         /*close winsock */
    2338             :         WSACleanup();
    2339             : #endif
    2340             : 
    2341             : #ifdef PHP_WIN32
    2342             :         php_win32_free_rng_lock();
    2343             : #endif
    2344             : 
    2345       20952 :         sapi_flush();
    2346             : 
    2347       20952 :         zend_shutdown();
    2348             : 
    2349             :         /* Destroys filter & transport registries too */
    2350       20952 :         php_shutdown_stream_wrappers(module_number);
    2351             : 
    2352       20952 :         UNREGISTER_INI_ENTRIES();
    2353             : 
    2354             :         /* close down the ini config */
    2355       20952 :         php_shutdown_config();
    2356             : 
    2357             : #ifndef ZTS
    2358       20952 :         zend_ini_shutdown();
    2359       20952 :         shutdown_memory_manager(CG(unclean_shutdown), 1);
    2360             : #else
    2361             :         zend_ini_global_shutdown();
    2362             : #endif
    2363             : 
    2364       20952 :         php_output_shutdown();
    2365             : 
    2366       20952 :         module_initialized = 0;
    2367             : 
    2368             : #ifndef ZTS
    2369       20952 :         core_globals_dtor(&core_globals);
    2370       20952 :         gc_globals_dtor();
    2371             : #else
    2372             :         ts_free_id(core_globals_id);
    2373             : #endif
    2374             : 
    2375             : #ifdef PHP_WIN32
    2376             :         if (old_invalid_parameter_handler == NULL) {
    2377             :                 _set_invalid_parameter_handler(old_invalid_parameter_handler);
    2378             :         }
    2379             : #endif
    2380             : }
    2381             : /* }}} */
    2382             : 
    2383             : /* {{{ php_execute_script
    2384             :  */
    2385       20814 : PHPAPI int php_execute_script(zend_file_handle *primary_file)
    2386             : {
    2387             :         zend_file_handle *prepend_file_p, *append_file_p;
    2388       20814 :         zend_file_handle prepend_file = {{0}, NULL, NULL, 0, 0}, append_file = {{0}, NULL, NULL, 0, 0};
    2389             : #if HAVE_BROKEN_GETCWD
    2390             :         volatile int old_cwd_fd = -1;
    2391             : #else
    2392             :         char *old_cwd;
    2393             :         ALLOCA_FLAG(use_heap)
    2394             : #endif
    2395       20814 :         int retval = 0;
    2396             : 
    2397       20814 :         EG(exit_status) = 0;
    2398             : #ifndef HAVE_BROKEN_GETCWD
    2399             : # define OLD_CWD_SIZE 4096
    2400       20814 :         old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
    2401       20814 :         old_cwd[0] = '\0';
    2402             : #endif
    2403             : 
    2404       20814 :         zend_try {
    2405             :                 char realfile[MAXPATHLEN];
    2406             : 
    2407             : #ifdef PHP_WIN32
    2408             :                 if(primary_file->filename) {
    2409             :                         UpdateIniFromRegistry((char*)primary_file->filename);
    2410             :                 }
    2411             : #endif
    2412             : 
    2413       20814 :                 PG(during_request_startup) = 0;
    2414             : 
    2415       20814 :                 if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
    2416             : #if HAVE_BROKEN_GETCWD
    2417             :                         /* this looks nasty to me */
    2418             :                         old_cwd_fd = open(".", 0);
    2419             : #else
    2420         239 :                         php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
    2421             : #endif
    2422         239 :                         VCWD_CHDIR_FILE(primary_file->filename);
    2423             :                 }
    2424             : 
    2425             :                 /* Only lookup the real file path and add it to the included_files list if already opened
    2426             :                  *   otherwise it will get opened and added to the included_files list in zend_execute_scripts
    2427             :                  */
    2428       82861 :                 if (primary_file->filename &&
    2429       20817 :                     (primary_file->filename[0] != '-' || primary_file->filename[1] != 0) &&
    2430       20811 :                         primary_file->opened_path == NULL &&
    2431       20419 :                         primary_file->type != ZEND_HANDLE_FILENAME
    2432             :                 ) {
    2433       20419 :                         if (expand_filepath(primary_file->filename, realfile)) {
    2434       40838 :                                 primary_file->opened_path = zend_string_init(realfile, strlen(realfile), 0);
    2435       20419 :                                 zend_hash_add_empty_element(&EG(included_files), primary_file->opened_path);
    2436             :                         }
    2437             :                 }
    2438             : 
    2439       20817 :                 if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
    2440           3 :                         prepend_file.filename = PG(auto_prepend_file);
    2441           3 :                         prepend_file.opened_path = NULL;
    2442           3 :                         prepend_file.free_filename = 0;
    2443           3 :                         prepend_file.type = ZEND_HANDLE_FILENAME;
    2444           3 :                         prepend_file_p = &prepend_file;
    2445             :                 } else {
    2446       20811 :                         prepend_file_p = NULL;
    2447             :                 }
    2448             : 
    2449       20814 :                 if (PG(auto_append_file) && PG(auto_append_file)[0]) {
    2450           0 :                         append_file.filename = PG(auto_append_file);
    2451           0 :                         append_file.opened_path = NULL;
    2452           0 :                         append_file.free_filename = 0;
    2453           0 :                         append_file.type = ZEND_HANDLE_FILENAME;
    2454           0 :                         append_file_p = &append_file;
    2455             :                 } else {
    2456       20814 :                         append_file_p = NULL;
    2457             :                 }
    2458       20814 :                 if (PG(max_input_time) != -1) {
    2459             : #ifdef PHP_WIN32
    2460             :                         zend_unset_timeout();
    2461             : #endif
    2462           0 :                         zend_set_timeout(INI_INT("max_execution_time"), 0);
    2463             :                 }
    2464             : 
    2465             :                 /*
    2466             :                    If cli primary file has shabang line and there is a prepend file,
    2467             :                    the `start_lineno` will be used by prepend file but not primary file,
    2468             :                    save it and restore after prepend file been executed.
    2469             :                  */
    2470       20817 :                 if (CG(start_lineno) && prepend_file_p) {
    2471           3 :                         int orig_start_lineno = CG(start_lineno);
    2472             : 
    2473           3 :                         CG(start_lineno) = 0;
    2474           3 :                         if (zend_execute_scripts(ZEND_REQUIRE, NULL, 1, prepend_file_p) == SUCCESS) {
    2475           3 :                                 CG(start_lineno) = orig_start_lineno;
    2476           3 :                                 retval = (zend_execute_scripts(ZEND_REQUIRE, NULL, 2, primary_file, append_file_p) == SUCCESS);
    2477             :                         }
    2478             :                 } else {
    2479       20811 :                         retval = (zend_execute_scripts(ZEND_REQUIRE, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
    2480             :                 }
    2481       20855 :         } zend_end_try();
    2482             : 
    2483       20855 :         if (EG(exception)) {
    2484          35 :                 zend_try {
    2485          35 :                         zend_exception_error(EG(exception), E_ERROR);
    2486          35 :                 } zend_end_try();
    2487             :         }
    2488             : 
    2489             : #if HAVE_BROKEN_GETCWD
    2490             :         if (old_cwd_fd != -1) {
    2491             :                 fchdir(old_cwd_fd);
    2492             :                 close(old_cwd_fd);
    2493             :         }
    2494             : #else
    2495       20855 :         if (old_cwd[0] != '\0') {
    2496         239 :                 php_ignore_value(VCWD_CHDIR(old_cwd));
    2497             :         }
    2498       20855 :         free_alloca(old_cwd, use_heap);
    2499             : #endif
    2500       20855 :         return retval;
    2501             : }
    2502             : /* }}} */
    2503             : 
    2504             : /* {{{ php_execute_simple_script
    2505             :  */
    2506           0 : PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval *ret)
    2507             : {
    2508             :         char *old_cwd;
    2509             :         ALLOCA_FLAG(use_heap)
    2510             : 
    2511           0 :         EG(exit_status) = 0;
    2512             : #define OLD_CWD_SIZE 4096
    2513           0 :         old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
    2514           0 :         old_cwd[0] = '\0';
    2515             : 
    2516           0 :         zend_try {
    2517             : #ifdef PHP_WIN32
    2518             :                 if(primary_file->filename) {
    2519             :                         UpdateIniFromRegistry((char*)primary_file->filename);
    2520             :                 }
    2521             : #endif
    2522             : 
    2523           0 :                 PG(during_request_startup) = 0;
    2524             : 
    2525           0 :                 if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
    2526           0 :                         php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
    2527           0 :                         VCWD_CHDIR_FILE(primary_file->filename);
    2528             :                 }
    2529           0 :                 zend_execute_scripts(ZEND_REQUIRE, ret, 1, primary_file);
    2530           0 :         } zend_end_try();
    2531             : 
    2532           0 :         if (old_cwd[0] != '\0') {
    2533           0 :                 php_ignore_value(VCWD_CHDIR(old_cwd));
    2534             :         }
    2535             : 
    2536           0 :         free_alloca(old_cwd, use_heap);
    2537           0 :         return EG(exit_status);
    2538             : }
    2539             : /* }}} */
    2540             : 
    2541             : /* {{{ php_handle_aborted_connection
    2542             :  */
    2543           6 : PHPAPI void php_handle_aborted_connection(void)
    2544             : {
    2545             : 
    2546           6 :         PG(connection_status) = PHP_CONNECTION_ABORTED;
    2547           6 :         php_output_set_status(PHP_OUTPUT_DISABLED);
    2548             : 
    2549           6 :         if (!PG(ignore_user_abort)) {
    2550           6 :                 zend_bailout();
    2551             :         }
    2552           0 : }
    2553             : /* }}} */
    2554             : 
    2555             : /* {{{ php_handle_auth_data
    2556             :  */
    2557         219 : PHPAPI int php_handle_auth_data(const char *auth)
    2558             : {
    2559         219 :         int ret = -1;
    2560             : 
    2561         219 :         if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
    2562             :                 char *pass;
    2563             :                 zend_string *user;
    2564             : 
    2565           0 :                 user = php_base64_decode((const unsigned char*)auth + 6, strlen(auth) - 6);
    2566           0 :                 if (user) {
    2567           0 :                         pass = strchr(user->val, ':');
    2568           0 :                         if (pass) {
    2569           0 :                                 *pass++ = '\0';
    2570           0 :                                 SG(request_info).auth_user = estrndup(user->val, user->len);
    2571           0 :                                 SG(request_info).auth_password = estrdup(pass);
    2572           0 :                                 ret = 0;
    2573             :                         }
    2574             :                         zend_string_free(user);
    2575             :                 }
    2576             :         }
    2577             : 
    2578         219 :         if (ret == -1) {
    2579         219 :                 SG(request_info).auth_user = SG(request_info).auth_password = NULL;
    2580             :         } else {
    2581           0 :                 SG(request_info).auth_digest = NULL;
    2582             :         }
    2583             : 
    2584         219 :         if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) {
    2585           0 :                 SG(request_info).auth_digest = estrdup(auth + 7);
    2586           0 :                 ret = 0;
    2587             :         }
    2588             : 
    2589         219 :         if (ret == -1) {
    2590         219 :                 SG(request_info).auth_digest = NULL;
    2591             :         }
    2592             : 
    2593         219 :         return ret;
    2594             : }
    2595             : /* }}} */
    2596             : 
    2597             : /* {{{ php_lint_script
    2598             :  */
    2599           5 : PHPAPI int php_lint_script(zend_file_handle *file)
    2600             : {
    2601             :         zend_op_array *op_array;
    2602           5 :         int retval = FAILURE;
    2603             : 
    2604           5 :         zend_try {
    2605           5 :                 op_array = zend_compile_file(file, ZEND_INCLUDE);
    2606           5 :                 zend_destroy_file_handle(file);
    2607             : 
    2608           5 :                 if (op_array) {
    2609           3 :                         destroy_op_array(op_array);
    2610           3 :                         efree(op_array);
    2611           3 :                         retval = SUCCESS;
    2612             :                 }
    2613           5 :         } zend_end_try();
    2614           5 :         if (EG(exception)) {
    2615           2 :                 zend_exception_error(EG(exception), E_ERROR);
    2616             :         }
    2617             : 
    2618           5 :         return retval;
    2619             : }
    2620             : /* }}} */
    2621             : 
    2622             : /*
    2623             :  * Local variables:
    2624             :  * tab-width: 4
    2625             :  * c-basic-offset: 4
    2626             :  * End:
    2627             :  * vim600: sw=4 ts=4 fdm=marker
    2628             :  * vim<600: sw=4 ts=4
    2629             :  */

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:59:09 +0000 (2 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.