123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787 |
- /*
- +----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2018 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@php.net> |
- | Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Zeev Suraski <zeev@php.net> |
- +----------------------------------------------------------------------+
- */
- /* {{{ includes
- */
- #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
- #include "php.h"
- #include <stdio.h>
- #include <fcntl.h>
- #ifdef PHP_WIN32
- #include "win32/time.h"
- #include "win32/signal.h"
- #include "win32/php_win32_globals.h"
- #include "win32/winutil.h"
- #include <process.h>
- #endif
- #if HAVE_SYS_TIME_H
- #include <sys/time.h>
- #endif
- #if HAVE_UNISTD_H
- #include <unistd.h>
- #endif
- #if HAVE_SIGNAL_H
- #include <signal.h>
- #endif
- #if HAVE_SETLOCALE
- #include <locale.h>
- #endif
- #include "zend.h"
- #include "zend_types.h"
- #include "zend_extensions.h"
- #include "php_ini.h"
- #include "php_globals.h"
- #include "php_main.h"
- #include "php_syslog.h"
- #include "fopen_wrappers.h"
- #include "ext/standard/php_standard.h"
- #include "ext/standard/php_string.h"
- #include "ext/date/php_date.h"
- #include "php_variables.h"
- #include "ext/standard/credits.h"
- #ifdef PHP_WIN32
- #include <io.h>
- #include "win32/php_registry.h"
- #include "ext/standard/flock_compat.h"
- #endif
- #include "php_syslog.h"
- #include "Zend/zend_exceptions.h"
- #if PHP_SIGCHILD
- #include <sys/types.h>
- #include <sys/wait.h>
- #endif
- #include "zend_compile.h"
- #include "zend_execute.h"
- #include "zend_highlight.h"
- #include "zend_extensions.h"
- #include "zend_ini.h"
- #include "zend_dtrace.h"
- #include "php_content_types.h"
- #include "php_ticks.h"
- #include "php_streams.h"
- #include "php_open_temporary_file.h"
- #include "SAPI.h"
- #include "rfc1867.h"
- #include "ext/standard/html_tables.h"
- #if HAVE_MMAP || defined(PHP_WIN32)
- # if HAVE_UNISTD_H
- # include <unistd.h>
- # if defined(_SC_PAGESIZE)
- # define REAL_PAGE_SIZE sysconf(_SC_PAGESIZE);
- # elif defined(_SC_PAGE_SIZE)
- # define REAL_PAGE_SIZE sysconf(_SC_PAGE_SIZE);
- # endif
- # endif
- # if HAVE_SYS_MMAN_H
- # include <sys/mman.h>
- # endif
- # ifndef REAL_PAGE_SIZE
- # ifdef PAGE_SIZE
- # define REAL_PAGE_SIZE PAGE_SIZE
- # else
- # define REAL_PAGE_SIZE 4096
- # endif
- # endif
- #endif
- /* }}} */
- PHPAPI int (*php_register_internal_extensions_func)(void) = php_register_internal_extensions;
- #ifndef ZTS
- php_core_globals core_globals;
- #else
- PHPAPI int core_globals_id;
- #endif
- #define SAFE_FILENAME(f) ((f)?(f):"-")
- static char *get_safe_charset_hint(void) {
- ZEND_TLS char *lastHint = NULL;
- ZEND_TLS char *lastCodeset = NULL;
- char *hint = SG(default_charset);
- size_t len = strlen(hint);
- size_t i = 0;
- if (lastHint == SG(default_charset)) {
- return lastCodeset;
- }
- lastHint = hint;
- lastCodeset = NULL;
- for (i = 0; i < sizeof(charset_map)/sizeof(charset_map[0]); i++) {
- if (len == charset_map[i].codeset_len
- && zend_binary_strcasecmp(hint, len, charset_map[i].codeset, len) == 0) {
- lastCodeset = (char*)charset_map[i].codeset;
- break;
- }
- }
- return lastCodeset;
- }
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnSetFacility)
- {
- const char *facility = ZSTR_VAL(new_value);
- #ifdef LOG_AUTH
- if (!strcmp(facility, "LOG_AUTH") || !strcmp(facility, "auth") || !strcmp(facility, "security")) {
- PG(syslog_facility) = LOG_AUTH;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_AUTHPRIV
- if (!strcmp(facility, "LOG_AUTHPRIV") || !strcmp(facility, "authpriv")) {
- PG(syslog_facility) = LOG_AUTHPRIV;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_CRON
- if (!strcmp(facility, "LOG_CRON") || !strcmp(facility, "cron")) {
- PG(syslog_facility) = LOG_CRON;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_DAEMON
- if (!strcmp(facility, "LOG_DAEMON") || !strcmp(facility, "daemon")) {
- PG(syslog_facility) = LOG_DAEMON;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_FTP
- if (!strcmp(facility, "LOG_FTP") || !strcmp(facility, "ftp")) {
- PG(syslog_facility) = LOG_FTP;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_KERN
- if (!strcmp(facility, "LOG_KERN") || !strcmp(facility, "kern")) {
- PG(syslog_facility) = LOG_KERN;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LPR
- if (!strcmp(facility, "LOG_LPR") || !strcmp(facility, "lpr")) {
- PG(syslog_facility) = LOG_LPR;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_MAIL
- if (!strcmp(facility, "LOG_MAIL") || !strcmp(facility, "mail")) {
- PG(syslog_facility) = LOG_MAIL;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_INTERNAL_MARK
- if (!strcmp(facility, "LOG_INTERNAL_MARK") || !strcmp(facility, "mark")) {
- PG(syslog_facility) = LOG_INTERNAL_MARK;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_NEWS
- if (!strcmp(facility, "LOG_NEWS") || !strcmp(facility, "news")) {
- PG(syslog_facility) = LOG_NEWS;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_SYSLOG
- if (!strcmp(facility, "LOG_SYSLOG") || !strcmp(facility, "syslog")) {
- PG(syslog_facility) = LOG_SYSLOG;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_USER
- if (!strcmp(facility, "LOG_USER") || !strcmp(facility, "user")) {
- PG(syslog_facility) = LOG_USER;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_UUCP
- if (!strcmp(facility, "LOG_UUCP") || !strcmp(facility, "uucp")) {
- PG(syslog_facility) = LOG_UUCP;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL0
- if (!strcmp(facility, "LOG_LOCAL0") || !strcmp(facility, "local0")) {
- PG(syslog_facility) = LOG_LOCAL0;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL1
- if (!strcmp(facility, "LOG_LOCAL1") || !strcmp(facility, "local1")) {
- PG(syslog_facility) = LOG_LOCAL1;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL2
- if (!strcmp(facility, "LOG_LOCAL2") || !strcmp(facility, "local2")) {
- PG(syslog_facility) = LOG_LOCAL2;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL3
- if (!strcmp(facility, "LOG_LOCAL3") || !strcmp(facility, "local3")) {
- PG(syslog_facility) = LOG_LOCAL3;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL4
- if (!strcmp(facility, "LOG_LOCAL4") || !strcmp(facility, "local4")) {
- PG(syslog_facility) = LOG_LOCAL4;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL5
- if (!strcmp(facility, "LOG_LOCAL5") || !strcmp(facility, "local5")) {
- PG(syslog_facility) = LOG_LOCAL5;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL6
- if (!strcmp(facility, "LOG_LOCAL6") || !strcmp(facility, "local6")) {
- PG(syslog_facility) = LOG_LOCAL6;
- return SUCCESS;
- }
- #endif
- #ifdef LOG_LOCAL7
- if (!strcmp(facility, "LOG_LOCAL7") || !strcmp(facility, "local7")) {
- PG(syslog_facility) = LOG_LOCAL7;
- return SUCCESS;
- }
- #endif
- return FAILURE;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnSetPrecision)
- {
- zend_long i;
- ZEND_ATOL(i, ZSTR_VAL(new_value));
- if (i >= -1) {
- EG(precision) = i;
- return SUCCESS;
- } else {
- return FAILURE;
- }
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnSetSerializePrecision)
- {
- zend_long i;
- ZEND_ATOL(i, ZSTR_VAL(new_value));
- if (i >= -1) {
- PG(serialize_precision) = i;
- return SUCCESS;
- } else {
- return FAILURE;
- }
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnChangeMemoryLimit)
- {
- if (new_value) {
- PG(memory_limit) = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
- } else {
- PG(memory_limit) = Z_L(1)<<30; /* effectively, no limit */
- }
- return zend_set_memory_limit(PG(memory_limit));
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnSetLogFilter)
- {
- const char *filter = ZSTR_VAL(new_value);
- if (!strcmp(filter, "all")) {
- PG(syslog_filter) = PHP_SYSLOG_FILTER_ALL;
- return SUCCESS;
- }
- if (!strcmp(filter, "no-ctrl")) {
- PG(syslog_filter) = PHP_SYSLOG_FILTER_NO_CTRL;
- return SUCCESS;
- }
- if (!strcmp(filter, "ascii")) {
- PG(syslog_filter) = PHP_SYSLOG_FILTER_ASCII;
- return SUCCESS;
- }
- if (!strcmp(filter, "raw")) {
- PG(syslog_filter) = PHP_SYSLOG_FILTER_RAW;
- return SUCCESS;
- }
- return FAILURE;
- }
- /* }}} */
- /* {{{ php_disable_functions
- */
- static void php_disable_functions(void)
- {
- char *s = NULL, *e;
- if (!*(INI_STR("disable_functions"))) {
- return;
- }
- e = PG(disable_functions) = strdup(INI_STR("disable_functions"));
- if (e == NULL) {
- return;
- }
- while (*e) {
- switch (*e) {
- case ' ':
- case ',':
- if (s) {
- *e = '\0';
- zend_disable_function(s, e-s);
- s = NULL;
- }
- break;
- default:
- if (!s) {
- s = e;
- }
- break;
- }
- e++;
- }
- if (s) {
- zend_disable_function(s, e-s);
- }
- }
- /* }}} */
- /* {{{ php_disable_classes
- */
- static void php_disable_classes(void)
- {
- char *s = NULL, *e;
- if (!*(INI_STR("disable_classes"))) {
- return;
- }
- e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
- while (*e) {
- switch (*e) {
- case ' ':
- case ',':
- if (s) {
- *e = '\0';
- zend_disable_class(s, e-s);
- s = NULL;
- }
- break;
- default:
- if (!s) {
- s = e;
- }
- break;
- }
- e++;
- }
- if (s) {
- zend_disable_class(s, e-s);
- }
- }
- /* }}} */
- /* {{{ php_binary_init
- */
- static void php_binary_init(void)
- {
- char *binary_location = NULL;
- #ifdef PHP_WIN32
- binary_location = (char *)malloc(MAXPATHLEN);
- if (binary_location && GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
- free(binary_location);
- PG(php_binary) = NULL;
- }
- #else
- if (sapi_module.executable_location) {
- binary_location = (char *)malloc(MAXPATHLEN);
- if (binary_location && !strchr(sapi_module.executable_location, '/')) {
- char *envpath, *path;
- int found = 0;
- if ((envpath = getenv("PATH")) != NULL) {
- char *search_dir, search_path[MAXPATHLEN];
- char *last = NULL;
- zend_stat_t s;
- path = estrdup(envpath);
- search_dir = php_strtok_r(path, ":", &last);
- while (search_dir) {
- snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
- if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK) && VCWD_STAT(binary_location, &s) == 0 && S_ISREG(s.st_mode)) {
- found = 1;
- break;
- }
- search_dir = php_strtok_r(NULL, ":", &last);
- }
- efree(path);
- }
- if (!found) {
- free(binary_location);
- binary_location = NULL;
- }
- } else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
- free(binary_location);
- binary_location = NULL;
- }
- }
- #endif
- PG(php_binary) = binary_location;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateTimeout)
- {
- if (stage==PHP_INI_STAGE_STARTUP) {
- /* Don't set a timeout on startup, only per-request */
- ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
- return SUCCESS;
- }
- zend_unset_timeout();
- ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
- zend_set_timeout(EG(timeout_seconds), 0);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ php_get_display_errors_mode() helper function
- */
- static int php_get_display_errors_mode(char *value, size_t value_length)
- {
- int mode;
- if (!value) {
- return PHP_DISPLAY_ERRORS_STDOUT;
- }
- if (value_length == 2 && !strcasecmp("on", value)) {
- mode = PHP_DISPLAY_ERRORS_STDOUT;
- } else if (value_length == 3 && !strcasecmp("yes", value)) {
- mode = PHP_DISPLAY_ERRORS_STDOUT;
- } else if (value_length == 4 && !strcasecmp("true", value)) {
- mode = PHP_DISPLAY_ERRORS_STDOUT;
- } else if (value_length == 6 && !strcasecmp(value, "stderr")) {
- mode = PHP_DISPLAY_ERRORS_STDERR;
- } else if (value_length == 6 && !strcasecmp(value, "stdout")) {
- mode = PHP_DISPLAY_ERRORS_STDOUT;
- } else {
- ZEND_ATOL(mode, value);
- if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
- mode = PHP_DISPLAY_ERRORS_STDOUT;
- }
- }
- return mode;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateDisplayErrors)
- {
- PG(display_errors) = (zend_bool) php_get_display_errors_mode(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_INI_DISP
- */
- static PHP_INI_DISP(display_errors_mode)
- {
- int mode, cgi_or_cli;
- size_t tmp_value_length;
- char *tmp_value;
- if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
- tmp_value = (ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : NULL );
- tmp_value_length = (ini_entry->orig_value? ZSTR_LEN(ini_entry->orig_value) : 0);
- } else if (ini_entry->value) {
- tmp_value = ZSTR_VAL(ini_entry->value);
- tmp_value_length = ZSTR_LEN(ini_entry->value);
- } else {
- tmp_value = NULL;
- tmp_value_length = 0;
- }
- mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
- /* Display 'On' for other SAPIs instead of STDOUT or STDERR */
- cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg"));
- switch (mode) {
- case PHP_DISPLAY_ERRORS_STDERR:
- if (cgi_or_cli ) {
- PUTS("STDERR");
- } else {
- PUTS("On");
- }
- break;
- case PHP_DISPLAY_ERRORS_STDOUT:
- if (cgi_or_cli ) {
- PUTS("STDOUT");
- } else {
- PUTS("On");
- }
- break;
- default:
- PUTS("Off");
- break;
- }
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateDefaultCharset)
- {
- OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
- if (new_value) {
- #ifdef PHP_WIN32
- php_win32_cp_do_update(ZSTR_VAL(new_value));
- #endif
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateInternalEncoding)
- {
- OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
- if (new_value) {
- #ifdef PHP_WIN32
- php_win32_cp_do_update(ZSTR_VAL(new_value));
- #endif
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateInputEncoding)
- {
- OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
- if (new_value) {
- #ifdef PHP_WIN32
- php_win32_cp_do_update(NULL);
- #endif
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateOutputEncoding)
- {
- OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
- if (new_value) {
- #ifdef PHP_WIN32
- php_win32_cp_do_update(NULL);
- #endif
- }
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateErrorLog)
- {
- /* Only do the safemode/open_basedir check at runtime */
- if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(ZSTR_VAL(new_value), "syslog")) {
- if (PG(open_basedir) && php_check_open_basedir(ZSTR_VAL(new_value))) {
- return FAILURE;
- }
- }
- OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnUpdateMailLog)
- {
- /* Only do the safemode/open_basedir check at runtime */
- if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {
- if (PG(open_basedir) && php_check_open_basedir(ZSTR_VAL(new_value))) {
- return FAILURE;
- }
- }
- OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
- return SUCCESS;
- }
- /* }}} */
- /* {{{ PHP_INI_MH
- */
- static PHP_INI_MH(OnChangeMailForceExtra)
- {
- /* Don't allow changing it in htaccess */
- if (stage == PHP_INI_STAGE_HTACCESS) {
- return FAILURE;
- }
- return SUCCESS;
- }
- /* }}} */
- /* defined in browscap.c */
- PHP_INI_MH(OnChangeBrowscap);
- /* Need to be read from the environment (?):
- * PHP_AUTO_PREPEND_FILE
- * PHP_AUTO_APPEND_FILE
- * PHP_DOCUMENT_ROOT
- * PHP_USER_DIR
- * PHP_INCLUDE_PATH
- */
- /* Windows use the internal mail */
- #if defined(PHP_WIN32)
- # define DEFAULT_SENDMAIL_PATH NULL
- #else
- # define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i"
- #endif
- /* {{{ PHP_INI
- */
- PHP_INI_BEGIN()
- PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
- PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
- PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
- PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
- PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
- STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode)
- STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateLong, xmlrpc_error_number, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("max_input_time", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, max_input_time, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_ALL, OnUpdateBool, implicit_flush, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateLong, log_errors_max_len, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_ALL, OnUpdateBool, report_memleaks, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("report_zend_debug", "1", PHP_INI_ALL, OnUpdateBool, report_zend_debug, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, output_buffering, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
- 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)
- STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("serialize_precision", "-1", PHP_INI_ALL, OnSetSerializePrecision, serialize_precision, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateDefaultCharset, default_charset, sapi_globals_struct, sapi_globals)
- STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct, sapi_globals)
- STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("output_encoding", NULL, PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
- PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
- STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_ALL, OnUpdateBaseDir, open_basedir, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
- STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
- 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)
- STD_PHP_INI_ENTRY("max_input_vars", "1000", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_vars, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("variables_order", "EGPCS", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("request_order", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, request_order, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("error_append_string", NULL, PHP_INI_ALL, OnUpdateString, error_append_string, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateString, error_prepend_string, php_core_globals, core_globals)
- PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL)
- PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL)
- STD_PHP_INI_BOOLEAN("mail.add_x_header", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, mail_x_header, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("mail.log", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateMailLog, mail_log, php_core_globals, core_globals)
- PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, OnChangeBrowscap)
- PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
- PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
- PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
- PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
- PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
- PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
- PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
- PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
- STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)
- 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)
- STD_PHP_INI_ENTRY("realpath_cache_size", "4096K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
- STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
- STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("hard_timeout", "2", PHP_INI_SYSTEM, OnUpdateLong, hard_timeout, zend_executor_globals, executor_globals)
- #ifdef PHP_WIN32
- STD_PHP_INI_BOOLEAN("windows.show_crt_warning", "0", PHP_INI_ALL, OnUpdateBool, windows_show_crt_warning, php_core_globals, core_globals)
- #endif
- STD_PHP_INI_ENTRY("syslog.facility", "LOG_USER", PHP_INI_SYSTEM, OnSetFacility, syslog_facility, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("syslog.ident", "php", PHP_INI_SYSTEM, OnUpdateString, syslog_ident, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("syslog.filter", "no-ctrl", PHP_INI_ALL, OnSetLogFilter, syslog_filter, php_core_globals, core_globals)
- PHP_INI_END()
- /* }}} */
- /* True globals (no need for thread safety */
- /* But don't make them a single int bitfield */
- static int module_initialized = 0;
- static int module_startup = 1;
- static int module_shutdown = 0;
- /* {{{ php_during_module_startup */
- static int php_during_module_startup(void)
- {
- return module_startup;
- }
- /* }}} */
- /* {{{ php_during_module_shutdown */
- static int php_during_module_shutdown(void)
- {
- return module_shutdown;
- }
- /* }}} */
- /* {{{ php_get_module_initialized
- */
- PHPAPI int php_get_module_initialized(void)
- {
- return module_initialized;
- }
- /* }}} */
- /* {{{ php_log_err_with_severity
- */
- PHPAPI ZEND_COLD void php_log_err_with_severity(char *log_message, int syslog_type_int)
- {
- int fd = -1;
- time_t error_time;
- if (PG(in_error_log)) {
- /* prevent recursive invocation */
- return;
- }
- PG(in_error_log) = 1;
- /* Try to use the specified logging location. */
- if (PG(error_log) != NULL) {
- #ifdef HAVE_SYSLOG_H
- if (!strcmp(PG(error_log), "syslog")) {
- php_syslog(syslog_type_int, "%s", log_message);
- PG(in_error_log) = 0;
- return;
- }
- #endif
- fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
- if (fd != -1) {
- char *tmp;
- size_t len;
- zend_string *error_time_str;
- time(&error_time);
- #ifdef ZTS
- if (!php_during_module_startup()) {
- error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1);
- } else {
- error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 0);
- }
- #else
- error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1);
- #endif
- len = spprintf(&tmp, 0, "[%s] %s%s", ZSTR_VAL(error_time_str), log_message, PHP_EOL);
- #ifdef PHP_WIN32
- php_flock(fd, 2);
- /* XXX should eventually write in a loop if len > UINT_MAX */
- php_ignore_value(write(fd, tmp, (unsigned)len));
- #else
- php_ignore_value(write(fd, tmp, len));
- #endif
- efree(tmp);
- zend_string_free(error_time_str);
- close(fd);
- PG(in_error_log) = 0;
- return;
- }
- }
- /* Otherwise fall back to the default logging location, if we have one */
- if (sapi_module.log_message) {
- sapi_module.log_message(log_message, syslog_type_int);
- }
- PG(in_error_log) = 0;
- }
- /* }}} */
- /* {{{ php_write
- wrapper for modules to use PHPWRITE */
- PHPAPI size_t php_write(void *buf, size_t size)
- {
- return PHPWRITE(buf, size);
- }
- /* }}} */
- /* {{{ php_printf
- */
- PHPAPI size_t php_printf(const char *format, ...)
- {
- va_list args;
- size_t ret;
- char *buffer;
- size_t size;
- va_start(args, format);
- size = vspprintf(&buffer, 0, format, args);
- ret = PHPWRITE(buffer, size);
- efree(buffer);
- va_end(args);
- return ret;
- }
- /* }}} */
- /* {{{ php_verror */
- /* php_verror is called from php_error_docref<n> functions.
- * Its purpose is to unify error messages and automatically generate clickable
- * html error messages if correcponding ini setting (html_errors) is activated.
- * See: CODING_STANDARDS for details.
- */
- PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int type, const char *format, va_list args)
- {
- zend_string *replace_buffer = NULL, *replace_origin = NULL;
- char *buffer = NULL, *docref_buf = NULL, *target = NULL;
- char *docref_target = "", *docref_root = "";
- char *p;
- int buffer_len = 0;
- const char *space = "";
- const char *class_name = "";
- const char *function;
- int origin_len;
- char *origin;
- char *message;
- int is_function = 0;
- /* get error text into buffer and escape for html if necessary */
- buffer_len = (int)vspprintf(&buffer, 0, format, args);
- if (PG(html_errors)) {
- replace_buffer = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, get_safe_charset_hint());
- /* Retry with substituting invalid chars on fail. */
- if (!replace_buffer || ZSTR_LEN(replace_buffer) < 1) {
- replace_buffer = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT | ENT_HTML_SUBSTITUTE_ERRORS, get_safe_charset_hint());
- }
- efree(buffer);
- if (replace_buffer) {
- buffer = ZSTR_VAL(replace_buffer);
- buffer_len = (int)ZSTR_LEN(replace_buffer);
- } else {
- buffer = "";
- buffer_len = 0;
- }
- }
- /* which function caused the problem if any at all */
- if (php_during_module_startup()) {
- function = "PHP Startup";
- } else if (php_during_module_shutdown()) {
- function = "PHP Shutdown";
- } else if (EG(current_execute_data) &&
- EG(current_execute_data)->func &&
- ZEND_USER_CODE(EG(current_execute_data)->func->common.type) &&
- EG(current_execute_data)->opline &&
- EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
- ) {
- switch (EG(current_execute_data)->opline->extended_value) {
- case ZEND_EVAL:
- function = "eval";
- is_function = 1;
- break;
- case ZEND_INCLUDE:
- function = "include";
- is_function = 1;
- break;
- case ZEND_INCLUDE_ONCE:
- function = "include_once";
- is_function = 1;
- break;
- case ZEND_REQUIRE:
- function = "require";
- is_function = 1;
- break;
- case ZEND_REQUIRE_ONCE:
- function = "require_once";
- is_function = 1;
- break;
- default:
- function = "Unknown";
- }
- } else {
- function = get_active_function_name();
- if (!function || !strlen(function)) {
- function = "Unknown";
- } else {
- is_function = 1;
- class_name = get_active_class_name(&space);
- }
- }
- /* if we still have memory then format the origin */
- if (is_function) {
- origin_len = (int)spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
- } else {
- origin_len = (int)spprintf(&origin, 0, "%s", function);
- }
- if (PG(html_errors)) {
- replace_origin = php_escape_html_entities((unsigned char*)origin, origin_len, 0, ENT_COMPAT, get_safe_charset_hint());
- efree(origin);
- origin = ZSTR_VAL(replace_origin);
- }
- /* origin and buffer available, so lets come up with the error message */
- if (docref && docref[0] == '#') {
- docref_target = strchr(docref, '#');
- docref = NULL;
- }
- /* no docref given but function is known (the default) */
- if (!docref && is_function) {
- int doclen;
- while (*function == '_') {
- function++;
- }
- if (space[0] == '\0') {
- doclen = (int)spprintf(&docref_buf, 0, "function.%s", function);
- } else {
- doclen = (int)spprintf(&docref_buf, 0, "%s.%s", class_name, function);
- }
- while((p = strchr(docref_buf, '_')) != NULL) {
- *p = '-';
- }
- docref = php_strtolower(docref_buf, doclen);
- }
- /* we have a docref for a function AND
- * - we show errors in html mode AND
- * - the user wants to see the links
- */
- if (docref && is_function && PG(html_errors) && strlen(PG(docref_root))) {
- if (strncmp(docref, "http://", 7)) {
- /* We don't have 'http://' so we use docref_root */
- char *ref; /* temp copy for duplicated docref */
- docref_root = PG(docref_root);
- ref = estrdup(docref);
- if (docref_buf) {
- efree(docref_buf);
- }
- docref_buf = ref;
- /* strip of the target if any */
- p = strrchr(ref, '#');
- if (p) {
- target = estrdup(p);
- if (target) {
- docref_target = target;
- *p = '\0';
- }
- }
- /* add the extension if it is set in ini */
- if (PG(docref_ext) && strlen(PG(docref_ext))) {
- spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext));
- efree(ref);
- }
- docref = docref_buf;
- }
- /* display html formatted or only show the additional links */
- if (PG(html_errors)) {
- spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer);
- } else {
- spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer);
- }
- if (target) {
- efree(target);
- }
- } else {
- spprintf(&message, 0, "%s: %s", origin, buffer);
- }
- if (replace_origin) {
- zend_string_free(replace_origin);
- } else {
- efree(origin);
- }
- if (docref_buf) {
- efree(docref_buf);
- }
- if (PG(track_errors) && module_initialized && EG(active) &&
- (Z_TYPE(EG(user_error_handler)) == IS_UNDEF || !(EG(user_error_handler_error_reporting) & type))) {
- zval tmp;
- ZVAL_STRINGL(&tmp, buffer, buffer_len);
- if (EG(current_execute_data)) {
- if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0) == FAILURE) {
- zval_ptr_dtor(&tmp);
- }
- } else {
- zend_hash_str_update_ind(&EG(symbol_table), "php_errormsg", sizeof("php_errormsg")-1, &tmp);
- }
- }
- if (replace_buffer) {
- zend_string_free(replace_buffer);
- } else {
- if (buffer_len > 0) {
- efree(buffer);
- }
- }
- php_error(type, "%s", message);
- efree(message);
- }
- /* }}} */
- /* {{{ php_error_docref0 */
- /* See: CODING_STANDARDS for details. */
- PHPAPI ZEND_COLD void php_error_docref0(const char *docref, int type, const char *format, ...)
- {
- va_list args;
- va_start(args, format);
- php_verror(docref, "", type, format, args);
- va_end(args);
- }
- /* }}} */
- /* {{{ php_error_docref1 */
- /* See: CODING_STANDARDS for details. */
- PHPAPI ZEND_COLD void php_error_docref1(const char *docref, const char *param1, int type, const char *format, ...)
- {
- va_list args;
- va_start(args, format);
- php_verror(docref, param1, type, format, args);
- va_end(args);
- }
- /* }}} */
- /* {{{ php_error_docref2 */
- /* See: CODING_STANDARDS for details. */
- PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1, const char *param2, int type, const char *format, ...)
- {
- char *params;
- va_list args;
- spprintf(¶ms, 0, "%s,%s", param1, param2);
- va_start(args, format);
- php_verror(docref, params ? params : "...", type, format, args);
- va_end(args);
- if (params) {
- efree(params);
- }
- }
- /* }}} */
- #ifdef PHP_WIN32
- #define PHP_WIN32_ERROR_MSG_BUFFER_SIZE 512
- PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2) {
- if (error == 0) {
- php_error_docref2(NULL, param1, param2, E_WARNING, "%s", strerror(errno));
- } else {
- char buf[PHP_WIN32_ERROR_MSG_BUFFER_SIZE + 1];
- size_t buf_len;
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL);
- buf_len = strlen(buf);
- if (buf_len >= 2) {
- buf[buf_len - 1] = '\0';
- buf[buf_len - 2] = '\0';
- }
- php_error_docref2(NULL, param1, param2, E_WARNING, "%s (code: %lu)", (char *)buf, error);
- }
- }
- #undef PHP_WIN32_ERROR_MSG_BUFFER_SIZE
- #endif
- /* {{{ php_html_puts */
- PHPAPI void php_html_puts(const char *str, size_t size)
- {
- zend_html_puts(str, size);
- }
- /* }}} */
- /* {{{ php_error_cb
- extended error handling function */
- static ZEND_COLD void php_error_cb(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args)
- {
- char *buffer;
- int buffer_len, display;
- buffer_len = (int)vspprintf(&buffer, PG(log_errors_max_len), format, args);
- /* check for repeated errors to be ignored */
- if (PG(ignore_repeated_errors) && PG(last_error_message)) {
- /* no check for PG(last_error_file) is needed since it cannot
- * be NULL if PG(last_error_message) is not NULL */
- if (strcmp(PG(last_error_message), buffer)
- || (!PG(ignore_repeated_source)
- && ((PG(last_error_lineno) != (int)error_lineno)
- || strcmp(PG(last_error_file), error_filename)))) {
- display = 1;
- } else {
- display = 0;
- }
- } else {
- display = 1;
- }
- /* according to error handling mode, throw exception or show it */
- if (EG(error_handling) == EH_THROW) {
- switch (type) {
- case E_ERROR:
- case E_CORE_ERROR:
- case E_COMPILE_ERROR:
- case E_USER_ERROR:
- case E_PARSE:
- /* fatal errors are real errors and cannot be made exceptions */
- break;
- case E_STRICT:
- case E_DEPRECATED:
- case E_USER_DEPRECATED:
- /* for the sake of BC to old damaged code */
- break;
- case E_NOTICE:
- case E_USER_NOTICE:
- /* notices are no errors and are not treated as such like E_WARNINGS */
- break;
- default:
- /* throw an exception if we are in EH_THROW mode
- * but DO NOT overwrite a pending exception
- */
- if (!EG(exception)) {
- zend_throw_error_exception(EG(exception_class), buffer, 0, type);
- }
- efree(buffer);
- return;
- }
- }
- /* store the error if it has changed */
- if (display) {
- if (PG(last_error_message)) {
- char *s = PG(last_error_message);
- PG(last_error_message) = NULL;
- free(s);
- }
- if (PG(last_error_file)) {
- char *s = PG(last_error_file);
- PG(last_error_file) = NULL;
- free(s);
- }
- if (!error_filename) {
- error_filename = "Unknown";
- }
- PG(last_error_type) = type;
- PG(last_error_message) = strdup(buffer);
- PG(last_error_file) = strdup(error_filename);
- PG(last_error_lineno) = error_lineno;
- }
- /* display/log the error if necessary */
- if (display && (EG(error_reporting) & type || (type & E_CORE))
- && (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
- char *error_type_str;
- int syslog_type_int = LOG_NOTICE;
- switch (type) {
- case E_ERROR:
- case E_CORE_ERROR:
- case E_COMPILE_ERROR:
- case E_USER_ERROR:
- error_type_str = "Fatal error";
- syslog_type_int = LOG_ERR;
- break;
- case E_RECOVERABLE_ERROR:
- error_type_str = "Recoverable fatal error";
- syslog_type_int = LOG_ERR;
- break;
- case E_WARNING:
- case E_CORE_WARNING:
- case E_COMPILE_WARNING:
- case E_USER_WARNING:
- error_type_str = "Warning";
- syslog_type_int = LOG_WARNING;
- break;
- case E_PARSE:
- error_type_str = "Parse error";
- syslog_type_int = LOG_ERR;
- break;
- case E_NOTICE:
- case E_USER_NOTICE:
- error_type_str = "Notice";
- syslog_type_int = LOG_NOTICE;
- break;
- case E_STRICT:
- error_type_str = "Strict Standards";
- syslog_type_int = LOG_INFO;
- break;
- case E_DEPRECATED:
- case E_USER_DEPRECATED:
- error_type_str = "Deprecated";
- syslog_type_int = LOG_INFO;
- break;
- default:
- error_type_str = "Unknown error";
- break;
- }
- if (!module_initialized || PG(log_errors)) {
- char *log_buffer;
- #ifdef PHP_WIN32
- if (type == E_CORE_ERROR || type == E_CORE_WARNING) {
- syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, buffer, GetCommandLine());
- }
- #endif
- spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %" PRIu32, error_type_str, buffer, error_filename, error_lineno);
- php_log_err_with_severity(log_buffer, syslog_type_int);
- efree(log_buffer);
- }
- if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) {
- if (PG(xmlrpc_errors)) {
- php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>" ZEND_LONG_FMT "</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %" PRIu32 "</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno);
- } else {
- char *prepend_string = INI_STR("error_prepend_string");
- char *append_string = INI_STR("error_append_string");
- if (PG(html_errors)) {
- if (type == E_ERROR || type == E_PARSE) {
- zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, get_safe_charset_hint());
- php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), error_filename, error_lineno, STR_PRINT(append_string));
- zend_string_free(buf);
- } else {
- php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
- }
- } else {
- /* Write CLI/CGI errors to stderr if display_errors = "stderr" */
- if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg")) &&
- PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
- ) {
- fprintf(stderr, "%s: %s in %s on line %" PRIu32 "\n", error_type_str, buffer, error_filename, error_lineno);
- #ifdef PHP_WIN32
- fflush(stderr);
- #endif
- } else {
- php_printf("%s\n%s: %s in %s on line %" PRIu32 "\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
- }
- }
- }
- }
- #if ZEND_DEBUG
- if (PG(report_zend_debug)) {
- zend_bool trigger_break;
- switch (type) {
- case E_ERROR:
- case E_CORE_ERROR:
- case E_COMPILE_ERROR:
- case E_USER_ERROR:
- trigger_break=1;
- break;
- default:
- trigger_break=0;
- break;
- }
- zend_output_debug_string(trigger_break, "%s(%" PRIu32 ") : %s - %s", error_filename, error_lineno, error_type_str, buffer);
- }
- #endif
- }
- /* Bail out if we can't recover */
- switch (type) {
- case E_CORE_ERROR:
- if(!module_initialized) {
- /* bad error in module startup - no way we can live with this */
- exit(-2);
- }
- /* no break - intentionally */
- case E_ERROR:
- case E_RECOVERABLE_ERROR:
- case E_PARSE:
- case E_COMPILE_ERROR:
- case E_USER_ERROR:
- EG(exit_status) = 255;
- if (module_initialized) {
- if (!PG(display_errors) &&
- !SG(headers_sent) &&
- SG(sapi_headers).http_response_code == 200
- ) {
- sapi_header_line ctr = {0};
- ctr.line = "HTTP/1.0 500 Internal Server Error";
- ctr.line_len = sizeof("HTTP/1.0 500 Internal Server Error") - 1;
- sapi_header_op(SAPI_HEADER_REPLACE, &ctr);
- }
- /* the parser would return 1 (failure), we can bail out nicely */
- if (type != E_PARSE) {
- /* restore memory limit */
- zend_set_memory_limit(PG(memory_limit));
- efree(buffer);
- zend_objects_store_mark_destructed(&EG(objects_store));
- zend_bailout();
- return;
- }
- }
- break;
- }
- /* Log if necessary */
- if (!display) {
- efree(buffer);
- return;
- }
- if (PG(track_errors) && module_initialized && EG(active)) {
- zval tmp;
- ZVAL_STRINGL(&tmp, buffer, buffer_len);
- if (EG(current_execute_data)) {
- if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0) == FAILURE) {
- zval_ptr_dtor(&tmp);
- }
- } else {
- zend_hash_str_update_ind(&EG(symbol_table), "php_errormsg", sizeof("php_errormsg")-1, &tmp);
- }
- }
- efree(buffer);
- }
- /* }}} */
- /* {{{ php_get_current_user
- */
- PHPAPI char *php_get_current_user(void)
- {
- zend_stat_t *pstat;
- if (SG(request_info).current_user) {
- return SG(request_info).current_user;
- }
- /* FIXME: I need to have this somehow handled if
- USE_SAPI is defined, because cgi will also be
- interfaced in USE_SAPI */
- pstat = sapi_get_stat();
- if (!pstat) {
- return "";
- } else {
- #ifdef PHP_WIN32
- char *name = php_win32_get_username();
- int len;
- if (!name) {
- return "";
- }
- len = (int)strlen(name);
- name[len] = '\0';
- SG(request_info).current_user_length = len;
- SG(request_info).current_user = estrndup(name, len);
- free(name);
- return SG(request_info).current_user;
- #else
- struct passwd *pwd;
- #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
- struct passwd _pw;
- struct passwd *retpwptr = NULL;
- int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
- char *pwbuf;
- if (pwbuflen < 1) {
- return "";
- }
- pwbuf = emalloc(pwbuflen);
- if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
- efree(pwbuf);
- return "";
- }
- if (retpwptr == NULL) {
- efree(pwbuf);
- return "";
- }
- pwd = &_pw;
- #else
- if ((pwd=getpwuid(pstat->st_uid))==NULL) {
- return "";
- }
- #endif
- SG(request_info).current_user_length = strlen(pwd->pw_name);
- SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
- #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
- efree(pwbuf);
- #endif
- return SG(request_info).current_user;
- #endif
- }
- }
- /* }}} */
- /* {{{ proto bool set_time_limit(int seconds)
- Sets the maximum time a script can run */
- PHP_FUNCTION(set_time_limit)
- {
- zend_long new_timeout;
- char *new_timeout_str;
- int new_timeout_strlen;
- zend_string *key;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &new_timeout) == FAILURE) {
- return;
- }
- new_timeout_strlen = (int)zend_spprintf(&new_timeout_str, 0, ZEND_LONG_FMT, new_timeout);
- key = zend_string_init("max_execution_time", sizeof("max_execution_time")-1, 0);
- if (zend_alter_ini_entry_chars_ex(key, new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == SUCCESS) {
- RETVAL_TRUE;
- } else {
- RETVAL_FALSE;
- }
- zend_string_release_ex(key, 0);
- efree(new_timeout_str);
- }
- /* }}} */
- /* {{{ php_fopen_wrapper_for_zend
- */
- static FILE *php_fopen_wrapper_for_zend(const char *filename, zend_string **opened_path)
- {
- return php_stream_open_wrapper_as_file((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
- }
- /* }}} */
- static void php_zend_stream_closer(void *handle) /* {{{ */
- {
- php_stream_close((php_stream*)handle);
- }
- /* }}} */
- static void php_zend_stream_mmap_closer(void *handle) /* {{{ */
- {
- php_stream_mmap_unmap((php_stream*)handle);
- php_zend_stream_closer(handle);
- }
- /* }}} */
- static size_t php_zend_stream_fsizer(void *handle) /* {{{ */
- {
- php_stream_statbuf ssb;
- if (php_stream_stat((php_stream*)handle, &ssb) == 0) {
- return ssb.sb.st_size;
- }
- return 0;
- }
- /* }}} */
- static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle) /* {{{ */
- {
- return php_stream_open_for_zend_ex(filename, handle, USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE);
- }
- /* }}} */
- PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode) /* {{{ */
- {
- char *p;
- size_t len, mapped_len;
- php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
- if (stream) {
- #if HAVE_MMAP || defined(PHP_WIN32)
- size_t page_size = REAL_PAGE_SIZE;
- #endif
- handle->filename = (char*)filename;
- handle->free_filename = 0;
- handle->handle.stream.handle = stream;
- handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
- handle->handle.stream.fsizer = php_zend_stream_fsizer;
- handle->handle.stream.isatty = 0;
- /* can we mmap immediately? */
- memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
- len = php_zend_stream_fsizer(stream);
- if (len != 0
- #if HAVE_MMAP || defined(PHP_WIN32)
- && ((len - 1) % page_size) <= page_size - ZEND_MMAP_AHEAD
- #endif
- && php_stream_mmap_possible(stream)
- && (p = php_stream_mmap_range(stream, 0, len, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped_len)) != NULL) {
- handle->handle.stream.closer = php_zend_stream_mmap_closer;
- handle->handle.stream.mmap.buf = p;
- handle->handle.stream.mmap.len = mapped_len;
- handle->type = ZEND_HANDLE_MAPPED;
- } else {
- handle->handle.stream.closer = php_zend_stream_closer;
- handle->type = ZEND_HANDLE_STREAM;
- }
- /* suppress warning if this stream is not explicitly closed */
- php_stream_auto_cleanup(stream);
- return SUCCESS;
- }
- return FAILURE;
- }
- /* }}} */
- static zend_string *php_resolve_path_for_zend(const char *filename, size_t filename_len) /* {{{ */
- {
- return php_resolve_path(filename, filename_len, PG(include_path));
- }
- /* }}} */
- /* {{{ php_get_configuration_directive_for_zend
- */
- static zval *php_get_configuration_directive_for_zend(zend_string *name)
- {
- return cfg_get_entry_ex(name);
- }
- /* }}} */
- /* {{{ php_free_request_globals
- */
- static void php_free_request_globals(void)
- {
- if (PG(last_error_message)) {
- free(PG(last_error_message));
- PG(last_error_message) = NULL;
- }
- if (PG(last_error_file)) {
- free(PG(last_error_file));
- PG(last_error_file) = NULL;
- }
- if (PG(php_sys_temp_dir)) {
- efree(PG(php_sys_temp_dir));
- PG(php_sys_temp_dir) = NULL;
- }
- }
- /* }}} */
- /* {{{ php_message_handler_for_zend
- */
- static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void *data)
- {
- switch (message) {
- case ZMSG_FAILED_INCLUDE_FOPEN:
- 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)));
- break;
- case ZMSG_FAILED_REQUIRE_FOPEN:
- 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)));
- break;
- case ZMSG_FAILED_HIGHLIGHT_FOPEN:
- php_error_docref(NULL, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
- break;
- case ZMSG_MEMORY_LEAK_DETECTED:
- case ZMSG_MEMORY_LEAK_REPEATED:
- #if ZEND_DEBUG
- if (EG(error_reporting) & E_WARNING) {
- char memory_leak_buf[1024];
- if (message==ZMSG_MEMORY_LEAK_DETECTED) {
- zend_leak_info *t = (zend_leak_info *) data;
- snprintf(memory_leak_buf, 512, "%s(%" PRIu32 ") : Freeing " ZEND_ADDR_FMT " (%zu bytes), script=%s\n", t->filename, t->lineno, (size_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
- if (t->orig_filename) {
- char relay_buf[512];
- snprintf(relay_buf, 512, "%s(%" PRIu32 ") : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
- strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf));
- }
- } else {
- unsigned long leak_count = (zend_uintptr_t) data;
- snprintf(memory_leak_buf, 512, "Last leak repeated %lu time%s\n", leak_count, (leak_count>1?"s":""));
- }
- # if defined(PHP_WIN32)
- OutputDebugString(memory_leak_buf);
- # else
- fprintf(stderr, "%s", memory_leak_buf);
- # endif
- }
- #endif
- break;
- case ZMSG_MEMORY_LEAKS_GRAND_TOTAL:
- #if ZEND_DEBUG
- if (EG(error_reporting) & E_WARNING) {
- char memory_leak_buf[512];
- snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((uint32_t *) data));
- # if defined(PHP_WIN32)
- OutputDebugString(memory_leak_buf);
- # else
- fprintf(stderr, "%s", memory_leak_buf);
- # endif
- }
- #endif
- break;
- case ZMSG_LOG_SCRIPT_NAME: {
- struct tm *ta, tmbuf;
- time_t curtime;
- char *datetime_str, asctimebuf[52];
- char memory_leak_buf[4096];
- time(&curtime);
- ta = php_localtime_r(&curtime, &tmbuf);
- datetime_str = php_asctime_r(ta, asctimebuf);
- if (datetime_str) {
- datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
- snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
- } else {
- snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null] Script: '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
- }
- # if defined(PHP_WIN32)
- OutputDebugString(memory_leak_buf);
- # else
- fprintf(stderr, "%s", memory_leak_buf);
- # endif
- }
- break;
- }
- }
- /* }}} */
- void php_on_timeout(int seconds)
- {
- PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
- }
- #if PHP_SIGCHILD
- /* {{{ sigchld_handler
- */
- static void sigchld_handler(int apar)
- {
- int errno_save = errno;
- while (waitpid(-1, NULL, WNOHANG) > 0);
- signal(SIGCHLD, sigchld_handler);
- errno = errno_save;
- }
- /* }}} */
- #endif
- /* {{{ php_request_startup
- */
- int php_request_startup(void)
- {
- int retval = SUCCESS;
- zend_interned_strings_activate();
- #ifdef HAVE_DTRACE
- 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));
- #endif /* HAVE_DTRACE */
- #ifdef PHP_WIN32
- # if defined(ZTS)
- _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
- # endif
- PG(com_initialized) = 0;
- #endif
- #if PHP_SIGCHILD
- signal(SIGCHLD, sigchld_handler);
- #endif
- zend_try {
- PG(in_error_log) = 0;
- PG(during_request_startup) = 1;
- php_output_activate();
- /* initialize global variables */
- PG(modules_activated) = 0;
- PG(header_is_being_sent) = 0;
- PG(connection_status) = PHP_CONNECTION_NORMAL;
- PG(in_user_include) = 0;
- zend_activate();
- sapi_activate();
- #ifdef ZEND_SIGNALS
- zend_signal_activate();
- #endif
- if (PG(max_input_time) == -1) {
- zend_set_timeout(EG(timeout_seconds), 1);
- } else {
- zend_set_timeout(PG(max_input_time), 1);
- }
- /* Disable realpath cache if an open_basedir is set */
- if (PG(open_basedir) && *PG(open_basedir)) {
- CWDG(realpath_cache_size_limit) = 0;
- }
- if (PG(expose_php)) {
- sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
- }
- if (PG(output_handler) && PG(output_handler)[0]) {
- zval oh;
- ZVAL_STRING(&oh, PG(output_handler));
- php_output_start_user(&oh, 0, PHP_OUTPUT_HANDLER_STDFLAGS);
- zval_ptr_dtor(&oh);
- } else if (PG(output_buffering)) {
- php_output_start_user(NULL, PG(output_buffering) > 1 ? PG(output_buffering) : 0, PHP_OUTPUT_HANDLER_STDFLAGS);
- } else if (PG(implicit_flush)) {
- php_output_set_implicit_flush(1);
- }
- /* We turn this off in php_execute_script() */
- /* PG(during_request_startup) = 0; */
- php_hash_environment();
- zend_activate_modules();
- PG(modules_activated)=1;
- } zend_catch {
- retval = FAILURE;
- } zend_end_try();
- SG(sapi_started) = 1;
- return retval;
- }
- /* }}} */
- /* {{{ php_request_shutdown_for_exec
- */
- void php_request_shutdown_for_exec(void *dummy)
- {
- /* used to close fd's in the 3..255 range here, but it's problematic
- */
- zend_interned_strings_deactivate();
- shutdown_memory_manager(1, 1);
- }
- /* }}} */
- /* {{{ php_request_shutdown
- */
- void php_request_shutdown(void *dummy)
- {
- zend_bool report_memleaks;
- EG(flags) |= EG_FLAGS_IN_SHUTDOWN;
- report_memleaks = PG(report_memleaks);
- /* EG(current_execute_data) points into nirvana and therefore cannot be safely accessed
- * inside zend_executor callback functions.
- */
- EG(current_execute_data) = NULL;
- php_deactivate_ticks();
- /* 1. Call all possible shutdown functions registered with register_shutdown_function() */
- if (PG(modules_activated)) zend_try {
- php_call_shutdown_functions();
- } zend_end_try();
- /* 2. Call all possible __destruct() functions */
- zend_try {
- zend_call_destructors();
- } zend_end_try();
- /* 3. Flush all output buffers */
- zend_try {
- zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;
- if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
- (size_t)PG(memory_limit) < zend_memory_usage(1)
- ) {
- send_buffer = 0;
- }
- if (!send_buffer) {
- php_output_discard_all();
- } else {
- php_output_end_all();
- }
- } zend_end_try();
- /* 4. Reset max_execution_time (no longer executing php code after response sent) */
- zend_try {
- zend_unset_timeout();
- } zend_end_try();
- /* 5. Call all extensions RSHUTDOWN functions */
- if (PG(modules_activated)) {
- zend_deactivate_modules();
- }
- /* 6. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */
- zend_try {
- php_output_deactivate();
- } zend_end_try();
- /* 7. Free shutdown functions */
- if (PG(modules_activated)) {
- php_free_shutdown_functions();
- }
- /* 8. Destroy super-globals */
- zend_try {
- int i;
- for (i=0; i<NUM_TRACK_VARS; i++) {
- zval_ptr_dtor(&PG(http_globals)[i]);
- }
- } zend_end_try();
- /* 9. free request-bound globals */
- php_free_request_globals();
- /* 10. Shutdown scanner/executor/compiler and restore ini entries */
- zend_deactivate();
- /* 11. Call all extensions post-RSHUTDOWN functions */
- zend_try {
- zend_post_deactivate_modules();
- } zend_end_try();
- /* 12. SAPI related shutdown (free stuff) */
- zend_try {
- sapi_deactivate();
- } zend_end_try();
- /* 13. free virtual CWD memory */
- virtual_cwd_deactivate();
- /* 14. Destroy stream hashes */
- zend_try {
- php_shutdown_stream_hashes();
- } zend_end_try();
- /* 15. Free Willy (here be crashes) */
- zend_interned_strings_deactivate();
- zend_try {
- shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0);
- } zend_end_try();
- /* 16. Reset max_execution_time */
- zend_try {
- zend_unset_timeout();
- } zend_end_try();
- /* 17. Deactivate Zend signals */
- #ifdef ZEND_SIGNALS
- zend_signal_deactivate();
- #endif
- #ifdef PHP_WIN32
- if (PG(com_initialized)) {
- CoUninitialize();
- PG(com_initialized) = 0;
- }
- #endif
- #ifdef HAVE_DTRACE
- 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));
- #endif /* HAVE_DTRACE */
- }
- /* }}} */
- /* {{{ php_com_initialize
- */
- PHPAPI void php_com_initialize(void)
- {
- #ifdef PHP_WIN32
- if (!PG(com_initialized)) {
- if (CoInitialize(NULL) == S_OK) {
- PG(com_initialized) = 1;
- }
- }
- #endif
- }
- /* }}} */
- /* {{{ php_output_wrapper
- */
- static size_t php_output_wrapper(const char *str, size_t str_length)
- {
- return php_output_write(str, str_length);
- }
- /* }}} */
- #ifdef ZTS
- /* {{{ core_globals_ctor
- */
- static void core_globals_ctor(php_core_globals *core_globals)
- {
- memset(core_globals, 0, sizeof(*core_globals));
- php_startup_ticks();
- }
- /* }}} */
- #endif
- /* {{{ core_globals_dtor
- */
- static void core_globals_dtor(php_core_globals *core_globals)
- {
- if (core_globals->last_error_message) {
- free(core_globals->last_error_message);
- }
- if (core_globals->last_error_file) {
- free(core_globals->last_error_file);
- }
- if (core_globals->disable_functions) {
- free(core_globals->disable_functions);
- }
- if (core_globals->disable_classes) {
- free(core_globals->disable_classes);
- }
- if (core_globals->php_binary) {
- free(core_globals->php_binary);
- }
- php_shutdown_ticks();
- }
- /* }}} */
- PHP_MINFO_FUNCTION(php_core) { /* {{{ */
- php_info_print_table_start();
- php_info_print_table_row(2, "PHP Version", PHP_VERSION);
- php_info_print_table_end();
- DISPLAY_INI_ENTRIES();
- }
- /* }}} */
- /* {{{ php_register_extensions
- */
- int php_register_extensions(zend_module_entry * const * ptr, int count)
- {
- zend_module_entry * const * end = ptr + count;
- while (ptr < end) {
- if (*ptr) {
- if (zend_register_internal_module(*ptr)==NULL) {
- return FAILURE;
- }
- }
- ptr++;
- }
- return SUCCESS;
- }
- /* A very long time ago php_module_startup() was refactored in a way
- * which broke calling it with more than one additional module.
- * This alternative to php_register_extensions() works around that
- * by walking the shallower structure.
- *
- * See algo: https://bugs.php.net/bug.php?id=63159
- */
- static int php_register_extensions_bc(zend_module_entry *ptr, int count)
- {
- while (count--) {
- if (zend_register_internal_module(ptr++) == NULL) {
- return FAILURE;
- }
- }
- return SUCCESS;
- }
- /* }}} */
- #ifdef PHP_WIN32
- static _invalid_parameter_handler old_invalid_parameter_handler;
- void dummy_invalid_parameter_handler(
- const wchar_t *expression,
- const wchar_t *function,
- const wchar_t *file,
- unsigned int line,
- uintptr_t pEwserved)
- {
- static int called = 0;
- char buf[1024];
- int len;
- if (!called) {
- if(PG(windows_show_crt_warning)) {
- called = 1;
- if (function) {
- if (file) {
- len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%u)", function, file, line);
- } else {
- len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function);
- }
- } else {
- len = _snprintf(buf, sizeof(buf)-1, "Invalid CRT parameter detected (function not known)");
- }
- zend_error(E_WARNING, "%s", buf);
- called = 0;
- }
- }
- }
- #endif
- /* {{{ php_module_startup
- */
- int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint32_t num_additional_modules)
- {
- zend_utility_functions zuf;
- zend_utility_values zuv;
- int retval = SUCCESS, module_number=0; /* for REGISTER_INI_ENTRIES() */
- char *php_os;
- zend_module_entry *module;
- #ifdef PHP_WIN32
- WORD wVersionRequested = MAKEWORD(2, 0);
- WSADATA wsaData;
- php_os = "WINNT";
- old_invalid_parameter_handler =
- _set_invalid_parameter_handler(dummy_invalid_parameter_handler);
- if (old_invalid_parameter_handler != NULL) {
- _set_invalid_parameter_handler(old_invalid_parameter_handler);
- }
- /* Disable the message box for assertions.*/
- _CrtSetReportMode(_CRT_ASSERT, 0);
- #else
- php_os = PHP_OS;
- #endif
- #ifdef ZTS
- (void)ts_resource(0);
- #endif
- #ifdef PHP_WIN32
- if (!php_win32_init_random_bytes()) {
- fprintf(stderr, "\ncrypt algorithm provider initialization failed\n");
- return FAILURE;
- }
- #endif
- module_shutdown = 0;
- module_startup = 1;
- sapi_initialize_empty_request();
- sapi_activate();
- if (module_initialized) {
- return SUCCESS;
- }
- sapi_module = *sf;
- php_output_startup();
- #ifdef ZTS
- ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
- #ifdef PHP_WIN32
- 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);
- #endif
- #else
- memset(&core_globals, 0, sizeof(core_globals));
- php_startup_ticks();
- #endif
- gc_globals_ctor();
- zuf.error_function = php_error_cb;
- zuf.printf_function = php_printf;
- zuf.write_function = php_output_wrapper;
- zuf.fopen_function = php_fopen_wrapper_for_zend;
- zuf.message_handler = php_message_handler_for_zend;
- zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
- zuf.ticks_function = php_run_ticks;
- zuf.on_timeout = php_on_timeout;
- zuf.stream_open_function = php_stream_open_for_zend;
- zuf.printf_to_smart_string_function = php_printf_to_smart_string;
- zuf.printf_to_smart_str_function = php_printf_to_smart_str;
- zuf.getenv_function = sapi_getenv;
- zuf.resolve_path_function = php_resolve_path_for_zend;
- zend_startup(&zuf, NULL);
- #if HAVE_SETLOCALE
- setlocale(LC_CTYPE, "");
- zend_update_current_locale();
- #endif
- #if HAVE_TZSET
- tzset();
- #endif
- #ifdef PHP_WIN32
- /* start up winsock services */
- if (WSAStartup(wVersionRequested, &wsaData) != 0) {
- php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
- return FAILURE;
- }
- #endif
- le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
- /* Register constants */
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_MAJOR_VERSION", PHP_MAJOR_VERSION, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_MINOR_VERSION", PHP_MINOR_VERSION, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_RELEASE_VERSION", PHP_RELEASE_VERSION, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTRA_VERSION", PHP_EXTRA_VERSION, sizeof(PHP_EXTRA_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_VERSION_ID", PHP_VERSION_ID, CONST_PERSISTENT | CONST_CS);
- #ifdef ZTS
- REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 1, CONST_PERSISTENT | CONST_CS);
- #else
- REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 0, CONST_PERSISTENT | CONST_CS);
- #endif
- REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS_FAMILY", PHP_OS_FAMILY, sizeof(PHP_OS_FAMILY)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE);
- REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
- #ifndef PHP_WIN32
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_MANDIR", PHP_MANDIR, sizeof(PHP_MANDIR)-1, CONST_PERSISTENT | CONST_CS);
- #endif
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS);
- 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);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", ZEND_LONG_MAX, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MIN", ZEND_LONG_MIN, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", SIZEOF_ZEND_LONG, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_FD_SETSIZE", FD_SETSIZE, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_FLOAT_DIG", DBL_DIG, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_DOUBLE_CONSTANT("PHP_FLOAT_EPSILON", DBL_EPSILON, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_DOUBLE_CONSTANT("PHP_FLOAT_MAX", DBL_MAX, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_DOUBLE_CONSTANT("PHP_FLOAT_MIN", DBL_MIN, CONST_PERSISTENT | CONST_CS);
- #ifdef PHP_WIN32
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MINOR", EG(windows_version_info).dwMinorVersion, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_BUILD", EG(windows_version_info).dwBuildNumber, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PLATFORM", EG(windows_version_info).dwPlatformId, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MAJOR", EG(windows_version_info).wServicePackMajor, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MINOR", EG(windows_version_info).wServicePackMinor, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SUITEMASK", EG(windows_version_info).wSuiteMask, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PRODUCTTYPE", EG(windows_version_info).wProductType, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_DOMAIN_CONTROLLER", VER_NT_DOMAIN_CONTROLLER, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_SERVER", VER_NT_SERVER, CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);
- #endif
- php_binary_init();
- if (PG(php_binary)) {
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE);
- } else {
- REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE);
- }
- php_output_register_constants();
- php_rfc1867_register_constants();
- /* this will read in php.ini, set up the configuration parameters,
- load zend extensions and register php function extensions
- to be loaded later */
- if (php_init_config() == FAILURE) {
- return FAILURE;
- }
- /* Register PHP core ini entries */
- REGISTER_INI_ENTRIES();
- /* Register Zend ini entries */
- zend_register_standard_ini_entries();
- #ifdef ZEND_WIN32
- /* Until the current ini values was setup, the current cp is 65001.
- If the actual ini vaues are different, some stuff needs to be updated.
- It concerns at least main_cwd_state and there might be more. As we're
- still in the startup phase, lets use the chance and reinit the relevant
- item according to the current codepage. Still, if ini_set() is used
- later on, a more intelligent way to update such stuff is needed.
- Startup/shutdown routines could involve touching globals and thus
- can't always be used on demand. */
- if (!php_win32_cp_use_unicode()) {
- virtual_cwd_main_cwd_init(1);
- }
- #endif
- /* Disable realpath cache if an open_basedir is set */
- if (PG(open_basedir) && *PG(open_basedir)) {
- CWDG(realpath_cache_size_limit) = 0;
- }
- PG(have_called_openlog) = 0;
- /* initialize stream wrappers registry
- * (this uses configuration parameters from php.ini)
- */
- if (php_init_stream_wrappers(module_number) == FAILURE) {
- php_printf("PHP: Unable to initialize stream url wrappers.\n");
- return FAILURE;
- }
- zuv.html_errors = 1;
- zuv.import_use_extension = ".php";
- zuv.import_use_extension_length = (uint32_t)strlen(zuv.import_use_extension);
- php_startup_auto_globals();
- zend_set_utility_values(&zuv);
- php_startup_sapi_content_types();
- /* startup extensions statically compiled in */
- if (php_register_internal_extensions_func() == FAILURE) {
- php_printf("Unable to start builtin modules\n");
- return FAILURE;
- }
- /* start additional PHP extensions */
- php_register_extensions_bc(additional_modules, num_additional_modules);
- /* load and startup extensions compiled as shared objects (aka DLLs)
- as requested by php.ini entries
- these are loaded after initialization of internal extensions
- as extensions *might* rely on things from ext/standard
- which is always an internal extension and to be initialized
- ahead of all other internals
- */
- php_ini_register_extensions();
- zend_startup_modules();
- /* start Zend extensions */
- zend_startup_extensions();
- zend_collect_module_handlers();
- /* register additional functions */
- if (sapi_module.additional_functions) {
- if ((module = zend_hash_str_find_ptr(&module_registry, "standard", sizeof("standard")-1)) != NULL) {
- EG(current_module) = module;
- zend_register_functions(NULL, sapi_module.additional_functions, NULL, MODULE_PERSISTENT);
- EG(current_module) = NULL;
- }
- }
- /* disable certain classes and functions as requested by php.ini */
- php_disable_functions();
- php_disable_classes();
- /* make core report what it should */
- if ((module = zend_hash_str_find_ptr(&module_registry, "core", sizeof("core")-1)) != NULL) {
- module->version = PHP_VERSION;
- module->info_func = PHP_MINFO(php_core);
- }
- if (zend_post_startup() != SUCCESS) {
- return FAILURE;
- }
- module_initialized = 1;
- /* Check for deprecated directives */
- /* NOTE: If you add anything here, remember to add it to Makefile.global! */
- {
- struct {
- const long error_level;
- const char *phrase;
- const char *directives[17]; /* Remember to change this if the number of directives change */
- } directives[2] = {
- {
- E_DEPRECATED,
- "Directive '%s' is deprecated",
- {
- "track_errors",
- NULL
- }
- },
- {
- E_CORE_ERROR,
- "Directive '%s' is no longer available in PHP",
- {
- "allow_call_time_pass_reference",
- "asp_tags",
- "define_syslog_variables",
- "highlight.bg",
- "magic_quotes_gpc",
- "magic_quotes_runtime",
- "magic_quotes_sybase",
- "register_globals",
- "register_long_arrays",
- "safe_mode",
- "safe_mode_gid",
- "safe_mode_include_dir",
- "safe_mode_exec_dir",
- "safe_mode_allowed_env_vars",
- "safe_mode_protected_env_vars",
- "zend.ze1_compatibility_mode",
- NULL
- }
- }
- };
- unsigned int i;
- zend_try {
- /* 2 = Count of deprecation structs */
- for (i = 0; i < 2; i++) {
- const char **p = directives[i].directives;
- while(*p) {
- zend_long value;
- if (cfg_get_long((char*)*p, &value) == SUCCESS && value) {
- zend_error(directives[i].error_level, directives[i].phrase, *p);
- }
- ++p;
- }
- }
- } zend_catch {
- retval = FAILURE;
- } zend_end_try();
- }
- virtual_cwd_deactivate();
- sapi_deactivate();
- module_startup = 0;
- shutdown_memory_manager(1, 0);
- virtual_cwd_activate();
- zend_interned_strings_switch_storage(1);
- #if ZEND_RC_DEBUG
- zend_rc_debug = 1;
- #endif
- /* we're done */
- return retval;
- }
- /* }}} */
- void php_module_shutdown_for_exec(void)
- {
- /* used to close fd's in the range 3.255 here, but it's problematic */
- }
- /* {{{ php_module_shutdown_wrapper
- */
- int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
- {
- php_module_shutdown();
- return SUCCESS;
- }
- /* }}} */
- /* {{{ php_module_shutdown
- */
- void php_module_shutdown(void)
- {
- int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
- module_shutdown = 1;
- if (!module_initialized) {
- return;
- }
- zend_interned_strings_switch_storage(0);
- #ifdef ZTS
- ts_free_worker_threads();
- #endif
- #if ZEND_RC_DEBUG
- zend_rc_debug = 0;
- #endif
- #ifdef PHP_WIN32
- (void)php_win32_shutdown_random_bytes();
- #endif
- sapi_flush();
- zend_shutdown();
- #ifdef PHP_WIN32
- /*close winsock */
- WSACleanup();
- #endif
- /* Destroys filter & transport registries too */
- php_shutdown_stream_wrappers(module_number);
- UNREGISTER_INI_ENTRIES();
- /* close down the ini config */
- php_shutdown_config();
- #ifndef ZTS
- zend_ini_shutdown();
- shutdown_memory_manager(CG(unclean_shutdown), 1);
- #else
- zend_ini_global_shutdown();
- #endif
- php_output_shutdown();
- #ifndef ZTS
- zend_interned_strings_dtor();
- #endif
- module_initialized = 0;
- #ifndef ZTS
- core_globals_dtor(&core_globals);
- gc_globals_dtor();
- #else
- ts_free_id(core_globals_id);
- #endif
- #ifdef PHP_WIN32
- if (old_invalid_parameter_handler == NULL) {
- _set_invalid_parameter_handler(old_invalid_parameter_handler);
- }
- #endif
- }
- /* }}} */
- /* {{{ php_execute_script
- */
- PHPAPI int php_execute_script(zend_file_handle *primary_file)
- {
- zend_file_handle *prepend_file_p, *append_file_p;
- zend_file_handle prepend_file = {{0}, NULL, NULL, 0, 0}, append_file = {{0}, NULL, NULL, 0, 0};
- #if HAVE_BROKEN_GETCWD
- volatile int old_cwd_fd = -1;
- #else
- char *old_cwd;
- ALLOCA_FLAG(use_heap)
- #endif
- int retval = 0;
- EG(exit_status) = 0;
- #ifndef HAVE_BROKEN_GETCWD
- # define OLD_CWD_SIZE 4096
- old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
- old_cwd[0] = '\0';
- #endif
- zend_try {
- char realfile[MAXPATHLEN];
- #ifdef PHP_WIN32
- if(primary_file->filename) {
- UpdateIniFromRegistry((char*)primary_file->filename);
- }
- #endif
- PG(during_request_startup) = 0;
- if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
- #if HAVE_BROKEN_GETCWD
- /* this looks nasty to me */
- old_cwd_fd = open(".", 0);
- #else
- php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
- #endif
- VCWD_CHDIR_FILE(primary_file->filename);
- }
- /* Only lookup the real file path and add it to the included_files list if already opened
- * otherwise it will get opened and added to the included_files list in zend_execute_scripts
- */
- if (primary_file->filename &&
- strcmp("Standard input code", primary_file->filename) &&
- primary_file->opened_path == NULL &&
- primary_file->type != ZEND_HANDLE_FILENAME
- ) {
- if (expand_filepath(primary_file->filename, realfile)) {
- primary_file->opened_path = zend_string_init(realfile, strlen(realfile), 0);
- zend_hash_add_empty_element(&EG(included_files), primary_file->opened_path);
- }
- }
- if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
- prepend_file.filename = PG(auto_prepend_file);
- prepend_file.opened_path = NULL;
- prepend_file.free_filename = 0;
- prepend_file.type = ZEND_HANDLE_FILENAME;
- prepend_file_p = &prepend_file;
- } else {
- prepend_file_p = NULL;
- }
- if (PG(auto_append_file) && PG(auto_append_file)[0]) {
- append_file.filename = PG(auto_append_file);
- append_file.opened_path = NULL;
- append_file.free_filename = 0;
- append_file.type = ZEND_HANDLE_FILENAME;
- append_file_p = &append_file;
- } else {
- append_file_p = NULL;
- }
- if (PG(max_input_time) != -1) {
- #ifdef PHP_WIN32
- zend_unset_timeout();
- #endif
- zend_set_timeout(INI_INT("max_execution_time"), 0);
- }
- /*
- If cli primary file has shabang line and there is a prepend file,
- the `start_lineno` will be used by prepend file but not primary file,
- save it and restore after prepend file been executed.
- */
- if (CG(start_lineno) && prepend_file_p) {
- int orig_start_lineno = CG(start_lineno);
- CG(start_lineno) = 0;
- if (zend_execute_scripts(ZEND_REQUIRE, NULL, 1, prepend_file_p) == SUCCESS) {
- CG(start_lineno) = orig_start_lineno;
- retval = (zend_execute_scripts(ZEND_REQUIRE, NULL, 2, primary_file, append_file_p) == SUCCESS);
- }
- } else {
- retval = (zend_execute_scripts(ZEND_REQUIRE, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
- }
- } zend_end_try();
- if (EG(exception)) {
- zend_try {
- zend_exception_error(EG(exception), E_ERROR);
- } zend_end_try();
- }
- #if HAVE_BROKEN_GETCWD
- if (old_cwd_fd != -1) {
- fchdir(old_cwd_fd);
- close(old_cwd_fd);
- }
- #else
- if (old_cwd[0] != '\0') {
- php_ignore_value(VCWD_CHDIR(old_cwd));
- }
- free_alloca(old_cwd, use_heap);
- #endif
- return retval;
- }
- /* }}} */
- /* {{{ php_execute_simple_script
- */
- PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval *ret)
- {
- char *old_cwd;
- ALLOCA_FLAG(use_heap)
- EG(exit_status) = 0;
- #define OLD_CWD_SIZE 4096
- old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
- old_cwd[0] = '\0';
- zend_try {
- #ifdef PHP_WIN32
- if(primary_file->filename) {
- UpdateIniFromRegistry((char*)primary_file->filename);
- }
- #endif
- PG(during_request_startup) = 0;
- if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
- php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
- VCWD_CHDIR_FILE(primary_file->filename);
- }
- zend_execute_scripts(ZEND_REQUIRE, ret, 1, primary_file);
- } zend_end_try();
- if (old_cwd[0] != '\0') {
- php_ignore_value(VCWD_CHDIR(old_cwd));
- }
- free_alloca(old_cwd, use_heap);
- return EG(exit_status);
- }
- /* }}} */
- /* {{{ php_handle_aborted_connection
- */
- PHPAPI void php_handle_aborted_connection(void)
- {
- PG(connection_status) = PHP_CONNECTION_ABORTED;
- php_output_set_status(PHP_OUTPUT_DISABLED);
- if (!PG(ignore_user_abort)) {
- zend_bailout();
- }
- }
- /* }}} */
- /* {{{ php_handle_auth_data
- */
- PHPAPI int php_handle_auth_data(const char *auth)
- {
- int ret = -1;
- if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
- char *pass;
- zend_string *user;
- user = php_base64_decode((const unsigned char*)auth + 6, strlen(auth) - 6);
- if (user) {
- pass = strchr(ZSTR_VAL(user), ':');
- if (pass) {
- *pass++ = '\0';
- SG(request_info).auth_user = estrndup(ZSTR_VAL(user), ZSTR_LEN(user));
- SG(request_info).auth_password = estrdup(pass);
- ret = 0;
- }
- zend_string_free(user);
- }
- }
- if (ret == -1) {
- SG(request_info).auth_user = SG(request_info).auth_password = NULL;
- } else {
- SG(request_info).auth_digest = NULL;
- }
- if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) {
- SG(request_info).auth_digest = estrdup(auth + 7);
- ret = 0;
- }
- if (ret == -1) {
- SG(request_info).auth_digest = NULL;
- }
- return ret;
- }
- /* }}} */
- /* {{{ php_lint_script
- */
- PHPAPI int php_lint_script(zend_file_handle *file)
- {
- zend_op_array *op_array;
- int retval = FAILURE;
- zend_try {
- op_array = zend_compile_file(file, ZEND_INCLUDE);
- zend_destroy_file_handle(file);
- if (op_array) {
- destroy_op_array(op_array);
- efree(op_array);
- retval = SUCCESS;
- }
- } zend_end_try();
- if (EG(exception)) {
- zend_exception_error(EG(exception), E_ERROR);
- }
- return retval;
- }
- /* }}} */
- /*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
|