2007-07-15 23:21:12 +08:00
/*
2000-02-20 07:21:46 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2014-09-20 00:33:14 +08:00
| PHP Version 7 |
1999-04-08 05:05:13 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2019-01-30 17:00:23 +08:00
| Copyright ( c ) The PHP Group |
1999-04-08 05:05:13 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 20:51:34 +08:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 21:13:16 +08:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-11 04:04:29 +08:00
| available through the world - wide - web at the following url : |
2006-01-01 20:51:34 +08:00
| http : //www.php.net/license/3_01.txt |
1999-07-16 21:13:16 +08:00
| 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 . |
1999-04-08 05:05:13 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2018-11-02 00:30:28 +08:00
| Authors : Andi Gutmans < andi @ php . net > |
1999-04-08 05:05:13 +08:00
| Rasmus Lerdorf < rasmus @ lerdorf . on . ca > |
2018-11-02 00:30:28 +08:00
| Zeev Suraski < zeev @ php . net > |
1999-04-08 05:05:13 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
1999-07-16 21:13:16 +08:00
*/
2001-06-06 21:06:12 +08:00
/* {{{ includes
*/
2003-02-17 21:29:59 +08:00
# define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
1999-04-08 05:05:13 +08:00
# include "php.h"
2003-03-02 18:19:15 +08:00
# include <stdio.h>
2007-04-06 21:58:48 +08:00
# include <fcntl.h>
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
1999-04-08 05:05:13 +08:00
# include "win32/time.h"
# include "win32/signal.h"
2006-05-25 06:00:15 +08:00
# include "win32/php_win32_globals.h"
2011-06-18 10:24:01 +08:00
# include "win32/winutil.h"
1999-04-08 05:05:13 +08:00
# include <process.h>
# endif
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
# if HAVE_UNISTD_H
# include <unistd.h>
# endif
2019-04-07 21:55:34 +08:00
1999-04-08 05:05:13 +08:00
# include <signal.h>
# include <locale.h>
# include "zend.h"
2014-08-26 02:22:49 +08:00
# include "zend_types.h"
2000-10-03 22:43:04 +08:00
# include "zend_extensions.h"
1999-04-08 05:05:13 +08:00
# include "php_ini.h"
1999-04-10 03:09:29 +08:00
# include "php_globals.h"
2015-04-05 04:11:37 +08:00
# include "php_main.h"
2017-08-12 02:30:50 +08:00
# include "php_syslog.h"
2001-02-24 06:07:16 +08:00
# include "fopen_wrappers.h"
1999-12-05 03:19:57 +08:00
# include "ext/standard/php_standard.h"
2007-12-29 10:21:57 +08:00
# include "ext/standard/php_string.h"
2009-05-05 03:55:47 +08:00
# include "ext/date/php_date.h"
2000-01-29 01:24:53 +08:00
# include "php_variables.h"
2000-11-21 06:31:38 +08:00
# include "ext/standard/credits.h"
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
1999-04-08 05:05:13 +08:00
# include <io.h>
1999-04-18 23:58:27 +08:00
# include "win32/php_registry.h"
2007-04-18 17:38:59 +08:00
# include "ext/standard/flock_compat.h"
1999-04-08 05:05:13 +08:00
# endif
2000-05-29 00:22:28 +08:00
# include "php_syslog.h"
2004-02-12 18:43:27 +08:00
# include "Zend/zend_exceptions.h"
1999-04-08 05:05:13 +08:00
2000-05-19 18:48:05 +08:00
# if PHP_SIGCHILD
# include <sys/types.h>
# include <sys/wait.h>
# endif
1999-04-08 05:05:13 +08:00
# include "zend_compile.h"
# include "zend_execute.h"
# include "zend_highlight.h"
2000-10-18 02:12:31 +08:00
# include "zend_extensions.h"
2002-11-18 06:52:47 +08:00
# include "zend_ini.h"
2010-04-24 21:32:30 +08:00
# include "zend_dtrace.h"
1999-04-08 05:05:13 +08:00
1999-09-17 07:18:15 +08:00
# include "php_content_types.h"
2000-02-26 05:27:03 +08:00
# include "php_ticks.h"
2002-03-16 05:03:08 +08:00
# include "php_streams.h"
2007-02-08 05:01:06 +08:00
# include "php_open_temporary_file.h"
1999-09-17 07:18:15 +08:00
1999-04-26 03:35:44 +08:00
# include "SAPI.h"
2002-07-12 09:49:58 +08:00
# include "rfc1867.h"
2009-04-28 15:13:30 +08:00
2017-09-21 07:02:52 +08:00
# include "ext/standard/html_tables.h"
2012-01-17 17:30:12 +08:00
# if HAVE_MMAP || defined(PHP_WIN32)
2011-10-16 09:19:55 +08:00
# 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
2009-04-28 15:13:30 +08:00
# endif
2009-04-30 17:11:00 +08:00
# endif
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-26 03:35:44 +08:00
2014-12-14 06:06:14 +08:00
PHPAPI int ( * php_register_internal_extensions_func ) ( void ) = php_register_internal_extensions ;
2008-08-22 20:59:46 +08:00
1999-04-10 03:09:29 +08:00
# ifndef ZTS
php_core_globals core_globals ;
1999-04-21 12:02:11 +08:00
# else
1999-04-26 22:00:49 +08:00
PHPAPI int core_globals_id ;
2019-03-14 08:01:01 +08:00
PHPAPI size_t core_globals_offset ;
1999-04-10 03:09:29 +08:00
# endif
1999-10-09 00:24:31 +08:00
1999-06-26 20:27:49 +08:00
# define SAFE_FILENAME(f) ((f)?(f):"-")
2017-09-21 07:02:52 +08:00
static char * get_safe_charset_hint ( void ) {
2017-09-21 16:32:09 +08:00
ZEND_TLS char * lastHint = NULL ;
ZEND_TLS char * lastCodeset = NULL ;
2017-09-21 07:02:52 +08:00
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 ;
}
2017-08-23 06:34:06 +08:00
/* {{{ 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 ;
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI_MH
*/
1999-04-11 00:25:23 +08:00
static PHP_INI_MH ( OnSetPrecision )
1999-04-10 03:09:29 +08:00
{
2014-08-26 01:24:55 +08:00
zend_long i ;
2014-08-16 17:16:11 +08:00
2015-06-30 18:59:27 +08:00
ZEND_ATOL ( i , ZSTR_VAL ( new_value ) ) ;
2015-08-31 14:50:15 +08:00
if ( i > = - 1 ) {
2006-12-26 06:36:57 +08:00
EG ( precision ) = i ;
return SUCCESS ;
} else {
return FAILURE ;
}
1999-04-10 03:09:29 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-10 03:09:29 +08:00
2015-08-05 07:12:10 +08:00
/* {{{ 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 ;
}
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI_MH
*/
1999-04-11 00:25:23 +08:00
static PHP_INI_MH ( OnChangeMemoryLimit )
{
if ( new_value ) {
2017-07-28 20:54:01 +08:00
PG ( memory_limit ) = zend_atol ( ZSTR_VAL ( new_value ) , ZSTR_LEN ( new_value ) ) ;
1999-04-11 00:25:23 +08:00
} else {
2017-11-22 01:48:37 +08:00
PG ( memory_limit ) = Z_L ( 1 ) < < 30 ; /* effectively, no limit */
1999-04-11 00:25:23 +08:00
}
2014-12-14 06:06:14 +08:00
return zend_set_memory_limit ( PG ( memory_limit ) ) ;
1999-04-11 00:25:23 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-11 00:25:23 +08:00
2017-08-12 02:30:50 +08:00
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnSetLogFilter )
{
2018-07-22 23:29:35 +08:00
const char * filter = ZSTR_VAL ( new_value ) ;
2017-08-12 02:30:50 +08:00
2018-07-22 23:29:35 +08:00
if ( ! strcmp ( filter , " all " ) ) {
PG ( syslog_filter ) = PHP_SYSLOG_FILTER_ALL ;
2017-08-12 02:30:50 +08:00
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 ;
}
2019-06-15 15:31:16 +08:00
if ( ! strcmp ( filter , " raw " ) ) {
PG ( syslog_filter ) = PHP_SYSLOG_FILTER_RAW ;
return SUCCESS ;
}
2017-08-12 02:30:50 +08:00
return FAILURE ;
}
/* }}} */
2010-03-12 18:28:59 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_disable_functions
*/
2014-12-14 06:06:14 +08:00
static void php_disable_functions ( void )
2000-05-30 01:22:35 +08:00
{
2003-12-25 00:38:22 +08:00
char * s = NULL , * e ;
2002-12-16 23:43:52 +08:00
2003-12-25 00:38:22 +08:00
if ( ! * ( INI_STR ( " disable_functions " ) ) ) {
2002-12-16 23:43:52 +08:00
return ;
}
2003-12-25 00:38:22 +08:00
e = PG ( disable_functions ) = strdup ( INI_STR ( " disable_functions " ) ) ;
2011-01-20 14:23:35 +08:00
if ( e = = NULL ) {
return ;
}
2002-12-16 23:43:52 +08:00
while ( * e ) {
switch ( * e ) {
case ' ' :
case ' , ' :
if ( s ) {
* e = ' \0 ' ;
2014-12-14 06:06:14 +08:00
zend_disable_function ( s , e - s ) ;
2002-12-16 23:43:52 +08:00
s = NULL ;
}
break ;
default :
if ( ! s ) {
s = e ;
}
break ;
}
e + + ;
}
if ( s ) {
2014-12-14 06:06:14 +08:00
zend_disable_function ( s , e - s ) ;
2000-05-30 01:22:35 +08:00
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-05-30 01:22:35 +08:00
2003-03-03 09:27:22 +08:00
/* {{{ php_disable_classes
*/
2014-12-14 06:06:14 +08:00
static void php_disable_classes ( void )
2003-03-03 09:27:22 +08:00
{
2003-12-25 00:38:22 +08:00
char * s = NULL , * e ;
2003-03-03 09:27:22 +08:00
2003-12-25 00:38:22 +08:00
if ( ! * ( INI_STR ( " disable_classes " ) ) ) {
2003-03-03 09:27:22 +08:00
return ;
}
2003-12-25 00:38:22 +08:00
e = PG ( disable_classes ) = strdup ( INI_STR ( " disable_classes " ) ) ;
2003-03-03 09:27:22 +08:00
while ( * e ) {
switch ( * e ) {
case ' ' :
case ' , ' :
if ( s ) {
* e = ' \0 ' ;
2014-12-14 06:06:14 +08:00
zend_disable_class ( s , e - s ) ;
2003-03-03 09:27:22 +08:00
s = NULL ;
}
break ;
default :
if ( ! s ) {
s = e ;
}
break ;
}
e + + ;
}
if ( s ) {
2014-12-14 06:06:14 +08:00
zend_disable_class ( s , e - s ) ;
2003-03-03 09:27:22 +08:00
}
}
/* }}} */
2011-12-07 18:33:13 +08:00
/* {{{ php_binary_init
*/
2014-12-14 06:06:14 +08:00
static void php_binary_init ( void )
2011-12-07 18:33:13 +08:00
{
2017-11-15 10:24:28 +08:00
char * binary_location = NULL ;
2011-12-07 18:33:13 +08:00
# ifdef PHP_WIN32
binary_location = ( char * ) malloc ( MAXPATHLEN ) ;
2017-11-15 10:24:28 +08:00
if ( binary_location & & GetModuleFileName ( 0 , binary_location , MAXPATHLEN ) = = 0 ) {
2011-12-07 18:33:13 +08:00
free ( binary_location ) ;
PG ( php_binary ) = NULL ;
}
# else
if ( sapi_module . executable_location ) {
binary_location = ( char * ) malloc ( MAXPATHLEN ) ;
2017-11-15 10:24:28 +08:00
if ( binary_location & & ! strchr ( sapi_module . executable_location , ' / ' ) ) {
2011-12-07 18:33:13 +08:00
char * envpath , * path ;
int found = 0 ;
if ( ( envpath = getenv ( " PATH " ) ) ! = NULL ) {
char * search_dir , search_path [ MAXPATHLEN ] ;
char * last = NULL ;
2014-08-26 02:22:49 +08:00
zend_stat_t s ;
2011-12-07 18:33:13 +08:00
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 ) ;
2013-07-09 21:05:10 +08:00
if ( VCWD_REALPATH ( search_path , binary_location ) & & ! VCWD_ACCESS ( binary_location , X_OK ) & & VCWD_STAT ( binary_location , & s ) = = 0 & & S_ISREG ( s . st_mode ) ) {
2011-12-07 18:33:13 +08:00
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 ;
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI_MH
*/
2000-06-16 10:27:47 +08:00
static PHP_INI_MH ( OnUpdateTimeout )
{
if ( stage = = PHP_INI_STAGE_STARTUP ) {
/* Don't set a timeout on startup, only per-request */
2015-06-30 18:59:27 +08:00
ZEND_ATOL ( EG ( timeout_seconds ) , ZSTR_VAL ( new_value ) ) ;
2000-06-16 10:27:47 +08:00
return SUCCESS ;
}
2014-12-14 06:06:14 +08:00
zend_unset_timeout ( ) ;
2015-06-30 18:59:27 +08:00
ZEND_ATOL ( EG ( timeout_seconds ) , ZSTR_VAL ( new_value ) ) ;
2008-03-19 05:42:50 +08:00
zend_set_timeout ( EG ( timeout_seconds ) , 0 ) ;
2000-06-16 10:27:47 +08:00
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-06-16 10:27:47 +08:00
2007-07-24 22:21:36 +08:00
/* {{{ php_get_display_errors_mode() helper function
*/
2017-07-28 21:07:09 +08:00
static int php_get_display_errors_mode ( char * value , size_t value_length )
2007-07-24 22:21:36 +08:00
{
int mode ;
2007-10-01 22:51:11 +08:00
if ( ! value ) {
return PHP_DISPLAY_ERRORS_STDOUT ;
}
2007-07-24 22:21:36 +08:00
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 ;
2007-10-01 22:51:11 +08:00
} else {
2014-08-26 02:22:49 +08:00
ZEND_ATOL ( mode , value ) ;
2007-07-24 22:21:36 +08:00
if ( mode & & mode ! = PHP_DISPLAY_ERRORS_STDOUT & & mode ! = PHP_DISPLAY_ERRORS_STDERR ) {
mode = PHP_DISPLAY_ERRORS_STDOUT ;
}
}
2010-03-12 18:28:59 +08:00
2007-07-24 22:21:36 +08:00
return mode ;
}
/* }}} */
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnUpdateDisplayErrors )
{
2017-07-28 21:07:09 +08:00
PG ( display_errors ) = ( zend_bool ) php_get_display_errors_mode ( ZSTR_VAL ( new_value ) , ZSTR_LEN ( new_value ) ) ;
2007-07-24 22:21:36 +08:00
return SUCCESS ;
}
/* }}} */
/* {{{ PHP_INI_DISP
*/
static PHP_INI_DISP ( display_errors_mode )
{
2017-07-28 21:07:09 +08:00
int mode , cgi_or_cli ;
size_t tmp_value_length ;
2007-07-24 22:21:36 +08:00
char * tmp_value ;
if ( type = = ZEND_INI_DISPLAY_ORIG & & ini_entry - > modified ) {
2015-06-30 18:59:27 +08:00
tmp_value = ( ini_entry - > orig_value ? ZSTR_VAL ( ini_entry - > orig_value ) : NULL ) ;
2017-07-28 21:07:09 +08:00
tmp_value_length = ( ini_entry - > orig_value ? ZSTR_LEN ( ini_entry - > orig_value ) : 0 ) ;
2007-07-24 22:21:36 +08:00
} else if ( ini_entry - > value ) {
2015-06-30 18:59:27 +08:00
tmp_value = ZSTR_VAL ( ini_entry - > value ) ;
2017-07-28 21:07:09 +08:00
tmp_value_length = ZSTR_LEN ( ini_entry - > value ) ;
2007-07-24 22:21:36 +08:00
} 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 */
2018-07-09 10:18:20 +08:00
cgi_or_cli = ( ! strcmp ( sapi_module . name , " cli " ) | | ! strcmp ( sapi_module . name , " cgi " ) | | ! strcmp ( sapi_module . name , " phpdbg " ) ) ;
2007-07-24 22:21:36 +08:00
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 ;
}
}
/* }}} */
2019-04-16 22:35:35 +08:00
PHPAPI const char * php_get_internal_encoding ( ) {
if ( PG ( internal_encoding ) & & PG ( internal_encoding ) [ 0 ] ) {
return PG ( internal_encoding ) ;
} else if ( SG ( default_charset ) ) {
return SG ( default_charset ) ;
}
return " " ;
}
PHPAPI const char * php_get_input_encoding ( ) {
if ( PG ( input_encoding ) & & PG ( input_encoding ) [ 0 ] ) {
return PG ( input_encoding ) ;
} else if ( SG ( default_charset ) ) {
return SG ( default_charset ) ;
}
return " " ;
}
PHPAPI const char * php_get_output_encoding ( ) {
if ( PG ( output_encoding ) & & PG ( output_encoding ) [ 0 ] ) {
return PG ( output_encoding ) ;
} else if ( SG ( default_charset ) ) {
return SG ( default_charset ) ;
}
return " " ;
}
PHPAPI void ( * php_internal_encoding_changed ) ( void ) = NULL ;
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnUpdateDefaultCharset )
{
if ( new_value ) {
OnUpdateString ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2019-04-16 22:35:35 +08:00
if ( php_internal_encoding_changed ) {
php_internal_encoding_changed ( ) ;
}
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
# ifdef PHP_WIN32
php_win32_cp_do_update ( ZSTR_VAL ( new_value ) ) ;
# endif
}
return SUCCESS ;
}
/* }}} */
2014-02-13 10:54:52 +08:00
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnUpdateInternalEncoding )
{
2014-03-24 10:04:35 +08:00
if ( new_value ) {
2014-12-14 06:06:14 +08:00
OnUpdateString ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2019-04-16 22:35:35 +08:00
if ( php_internal_encoding_changed ) {
php_internal_encoding_changed ( ) ;
}
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
# ifdef PHP_WIN32
php_win32_cp_do_update ( ZSTR_VAL ( new_value ) ) ;
# endif
2014-02-13 10:54:52 +08:00
}
return SUCCESS ;
}
/* }}} */
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnUpdateInputEncoding )
{
2014-03-24 10:04:35 +08:00
if ( new_value ) {
2014-12-14 06:06:14 +08:00
OnUpdateString ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2019-04-16 22:35:35 +08:00
if ( php_internal_encoding_changed ) {
php_internal_encoding_changed ( ) ;
}
2016-12-14 09:51:29 +08:00
# ifdef PHP_WIN32
php_win32_cp_do_update ( NULL ) ;
# endif
2014-02-13 10:54:52 +08:00
}
return SUCCESS ;
}
/* }}} */
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnUpdateOutputEncoding )
{
2014-03-24 10:04:35 +08:00
if ( new_value ) {
2014-12-14 06:06:14 +08:00
OnUpdateString ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2019-04-16 22:35:35 +08:00
if ( php_internal_encoding_changed ) {
php_internal_encoding_changed ( ) ;
}
2016-12-14 09:51:29 +08:00
# ifdef PHP_WIN32
php_win32_cp_do_update ( NULL ) ;
# endif
2014-02-13 10:54:52 +08:00
}
return SUCCESS ;
}
/* }}} */
2007-08-03 09:15:51 +08:00
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnUpdateErrorLog )
{
/* Only do the safemode/open_basedir check at runtime */
2015-06-30 18:59:27 +08:00
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 ) ) ) {
2007-08-03 09:15:51 +08:00
return FAILURE ;
}
}
2014-12-14 06:06:14 +08:00
OnUpdateString ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2007-08-03 09:15:51 +08:00
return SUCCESS ;
}
/* }}} */
2009-07-09 08:21:17 +08:00
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH ( OnUpdateMailLog )
{
/* Only do the safemode/open_basedir check at runtime */
2009-07-13 00:38:14 +08:00
if ( ( stage = = PHP_INI_STAGE_RUNTIME | | stage = = PHP_INI_STAGE_HTACCESS ) & & new_value ) {
2015-06-30 18:59:27 +08:00
if ( PG ( open_basedir ) & & php_check_open_basedir ( ZSTR_VAL ( new_value ) ) ) {
2009-07-09 08:21:17 +08:00
return FAILURE ;
}
}
2014-12-14 06:06:14 +08:00
OnUpdateString ( entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage ) ;
2009-07-09 08:21:17 +08:00
return SUCCESS ;
}
/* }}} */
2007-09-14 04:04:22 +08:00
/* {{{ 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 ;
}
/* }}} */
2011-05-02 02:37:20 +08:00
/* defined in browscap.c */
PHP_INI_MH ( OnChangeBrowscap ) ;
2007-09-14 04:04:22 +08:00
2010-04-27 07:53:30 +08:00
/* Need to be read from the environment (?):
1999-04-10 21:32:47 +08:00
* PHP_AUTO_PREPEND_FILE
* PHP_AUTO_APPEND_FILE
1999-04-11 00:25:23 +08:00
* PHP_DOCUMENT_ROOT
* PHP_USER_DIR
* PHP_INCLUDE_PATH
1999-04-10 20:17:20 +08:00
*/
1999-04-10 21:32:47 +08:00
2016-11-12 18:20:01 +08:00
/* Windows use the internal mail */
# if defined(PHP_WIN32)
2008-08-27 07:26:07 +08:00
# define DEFAULT_SENDMAIL_PATH NULL
# elif defined(PHP_PROG_SENDMAIL)
# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
1999-04-10 21:32:47 +08:00
# else
2008-08-27 07:26:07 +08:00
# define DEFAULT_SENDMAIL_PATH " / usr / sbin / sendmail -t -i"
1999-04-10 21:32:47 +08:00
# endif
2008-08-27 07:26:07 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ PHP_INI
*/
1999-04-10 03:09:29 +08:00
PHP_INI_BEGIN ( )
2000-02-25 06:00:47 +08:00
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 )
2007-07-24 22:21:36 +08:00
STD_PHP_INI_ENTRY_EX ( " display_errors " , " 1 " , PHP_INI_ALL , OnUpdateDisplayErrors , display_errors , php_core_globals , core_globals , display_errors_mode )
2000-09-09 23:02:15 +08:00
STD_PHP_INI_BOOLEAN ( " display_startup_errors " , " 0 " , PHP_INI_ALL , OnUpdateBool , display_startup_errors , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
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 )
2003-03-19 06:21:54 +08:00
STD_PHP_INI_ENTRY ( " docref_root " , " " , PHP_INI_ALL , OnUpdateString , docref_root , php_core_globals , core_globals )
2002-08-09 03:12:27 +08:00
STD_PHP_INI_ENTRY ( " docref_ext " , " " , PHP_INI_ALL , OnUpdateString , docref_ext , php_core_globals , core_globals )
2003-03-19 06:21:54 +08:00
STD_PHP_INI_BOOLEAN ( " html_errors " , " 1 " , PHP_INI_ALL , OnUpdateBool , html_errors , php_core_globals , core_globals )
2001-07-10 23:59:33 +08:00
STD_PHP_INI_BOOLEAN ( " xmlrpc_errors " , " 0 " , PHP_INI_SYSTEM , OnUpdateBool , xmlrpc_errors , php_core_globals , core_globals )
2003-03-07 13:15:28 +08:00
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 )
2000-05-31 22:02:36 +08:00
STD_PHP_INI_BOOLEAN ( " ignore_user_abort " , " 0 " , PHP_INI_ALL , OnUpdateBool , ignore_user_abort , php_core_globals , core_globals )
2002-10-23 17:31:33 +08:00
STD_PHP_INI_BOOLEAN ( " implicit_flush " , " 0 " , PHP_INI_ALL , OnUpdateBool , implicit_flush , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_BOOLEAN ( " log_errors " , " 0 " , PHP_INI_ALL , OnUpdateBool , log_errors , php_core_globals , core_globals )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_ENTRY ( " log_errors_max_len " , " 1024 " , PHP_INI_ALL , OnUpdateLong , log_errors_max_len , php_core_globals , core_globals )
2002-04-07 02:49:59 +08:00
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 )
2002-10-25 00:56:59 +08:00
STD_PHP_INI_BOOLEAN ( " report_memleaks " , " 1 " , PHP_INI_ALL , OnUpdateBool , report_memleaks , php_core_globals , core_globals )
2002-11-21 22:56:06 +08:00
STD_PHP_INI_BOOLEAN ( " report_zend_debug " , " 1 " , PHP_INI_ALL , OnUpdateBool , report_zend_debug , php_core_globals , core_globals )
2003-03-07 13:15:28 +08:00
STD_PHP_INI_ENTRY ( " output_buffering " , " 0 " , PHP_INI_PERDIR | PHP_INI_SYSTEM , OnUpdateLong , output_buffering , php_core_globals , core_globals )
2002-10-23 17:35:21 +08:00
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 )
2004-03-17 03:49:19 +08:00
STD_PHP_INI_BOOLEAN ( " auto_globals_jit " , " 1 " , PHP_INI_PERDIR | PHP_INI_SYSTEM , OnUpdateBool , auto_globals_jit , php_core_globals , core_globals )
2008-03-22 20:56:16 +08:00
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 )
2000-02-25 06:00:47 +08:00
2002-10-23 17:35:21 +08:00
STD_PHP_INI_ENTRY ( " unserialize_callback_func " , NULL , PHP_INI_ALL , OnUpdateString , unserialize_callback_func , php_core_globals , core_globals )
2015-08-05 07:12:10 +08:00
STD_PHP_INI_ENTRY ( " serialize_precision " , " -1 " , PHP_INI_ALL , OnSetSerializePrecision , serialize_precision , php_core_globals , core_globals )
2001-04-05 04:46:26 +08:00
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 )
2002-07-12 03:38:08 +08:00
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 )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_ENTRY ( " doc_root " , NULL , PHP_INI_SYSTEM , OnUpdateStringUnempty , doc_root , php_core_globals , core_globals )
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
STD_PHP_INI_ENTRY ( " default_charset " , PHP_DEFAULT_CHARSET , PHP_INI_ALL , OnUpdateDefaultCharset , default_charset , sapi_globals_struct , sapi_globals )
2014-02-13 10:54:52 +08:00
STD_PHP_INI_ENTRY ( " default_mimetype " , SAPI_DEFAULT_MIMETYPE , PHP_INI_ALL , OnUpdateString , default_mimetype , sapi_globals_struct , sapi_globals )
2014-03-24 10:04:35 +08:00
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 )
2007-08-03 09:15:51 +08:00
STD_PHP_INI_ENTRY ( " error_log " , NULL , PHP_INI_ALL , OnUpdateErrorLog , error_log , php_core_globals , core_globals )
2000-05-02 22:46:20 +08:00
STD_PHP_INI_ENTRY ( " extension_dir " , PHP_EXTENSION_DIR , PHP_INI_SYSTEM , OnUpdateStringUnempty , extension_dir , php_core_globals , core_globals )
2013-01-19 00:13:39 +08:00
STD_PHP_INI_ENTRY ( " sys_temp_dir " , NULL , PHP_INI_SYSTEM , OnUpdateStringUnempty , sys_temp_dir , php_core_globals , core_globals )
2000-07-18 19:02:28 +08:00
STD_PHP_INI_ENTRY ( " include_path " , PHP_INCLUDE_PATH , PHP_INI_ALL , OnUpdateStringUnempty , include_path , php_core_globals , core_globals )
2000-06-16 10:27:47 +08:00
PHP_INI_ENTRY ( " max_execution_time " , " 30 " , PHP_INI_ALL , OnUpdateTimeout )
2008-12-09 18:23:44 +08:00
STD_PHP_INI_ENTRY ( " open_basedir " , NULL , PHP_INI_ALL , OnUpdateBaseDir , open_basedir , php_core_globals , core_globals )
2002-07-26 01:31:34 +08:00
STD_PHP_INI_BOOLEAN ( " file_uploads " , " 1 " , PHP_INI_SYSTEM , OnUpdateBool , file_uploads , php_core_globals , core_globals )
2003-03-07 13:15:28 +08:00
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 )
2000-02-25 06:00:47 +08:00
STD_PHP_INI_ENTRY ( " upload_tmp_dir " , NULL , PHP_INI_SYSTEM , OnUpdateStringUnempty , upload_tmp_dir , php_core_globals , core_globals )
2007-03-03 05:58:05 +08:00
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 )
2011-12-14 16:56:35 +08:00
STD_PHP_INI_ENTRY ( " max_input_vars " , " 1000 " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateLongGEZero , max_input_vars , php_core_globals , core_globals )
2002-07-26 01:31:34 +08:00
2003-02-16 04:22:19 +08:00
STD_PHP_INI_ENTRY ( " user_dir " , NULL , PHP_INI_SYSTEM , OnUpdateString , user_dir , php_core_globals , core_globals )
2005-08-06 05:44:26 +08:00
STD_PHP_INI_ENTRY ( " variables_order " , " EGPCS " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateStringUnempty , variables_order , php_core_globals , core_globals )
2008-03-13 04:24:45 +08:00
STD_PHP_INI_ENTRY ( " request_order " , NULL , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateString , request_order , php_core_globals , core_globals )
2000-02-25 06:00:47 +08:00
2002-11-19 22:11:50 +08:00
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 )
2001-05-06 23:22:22 +08:00
2000-02-25 06:00:47 +08:00
PHP_INI_ENTRY ( " SMTP " , " localhost " , PHP_INI_ALL , NULL )
2002-06-03 01:13:48 +08:00
PHP_INI_ENTRY ( " smtp_port " , " 25 " , PHP_INI_ALL , NULL )
2009-01-09 22:59:30 +08:00
STD_PHP_INI_BOOLEAN ( " mail.add_x_header " , " 0 " , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateBool , mail_x_header , php_core_globals , core_globals )
2009-07-09 08:21:17 +08:00
STD_PHP_INI_ENTRY ( " mail.log " , NULL , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnUpdateMailLog , mail_log , php_core_globals , core_globals )
2011-05-02 02:37:20 +08:00
PHP_INI_ENTRY ( " browscap " , NULL , PHP_INI_SYSTEM , OnChangeBrowscap )
2006-12-21 17:12:42 +08:00
PHP_INI_ENTRY ( " memory_limit " , " 128M " , PHP_INI_ALL , OnChangeMemoryLimit )
2000-02-25 06:00:47 +08:00
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 )
2007-09-14 04:04:22 +08:00
PHP_INI_ENTRY ( " mail.force_extra_parameters " , NULL , PHP_INI_SYSTEM | PHP_INI_PERDIR , OnChangeMailForceExtra )
2000-07-14 01:52:00 +08:00
PHP_INI_ENTRY ( " disable_functions " , " " , PHP_INI_SYSTEM , NULL )
2003-03-03 09:27:22 +08:00
PHP_INI_ENTRY ( " disable_classes " , " " , PHP_INI_SYSTEM , NULL )
2012-02-18 01:54:11 +08:00
PHP_INI_ENTRY ( " max_file_uploads " , " 20 " , PHP_INI_SYSTEM | PHP_INI_PERDIR , NULL )
2000-10-13 08:09:31 +08:00
2007-09-28 10:05:10 +08:00
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 )
2010-12-10 04:35:59 +08:00
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 )
2007-08-31 16:35:37 +08:00
2017-01-05 17:18:48 +08:00
STD_PHP_INI_ENTRY ( " realpath_cache_size " , " 4096K " , PHP_INI_SYSTEM , OnUpdateLong , realpath_cache_size_limit , virtual_cwd_globals , cwd_globals )
2007-08-31 16:35:37 +08:00
STD_PHP_INI_ENTRY ( " realpath_cache_ttl " , " 120 " , PHP_INI_SYSTEM , OnUpdateLong , realpath_cache_ttl , virtual_cwd_globals , cwd_globals )
2007-09-28 10:05:10 +08:00
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 )
2016-04-20 18:52:21 +08:00
STD_PHP_INI_ENTRY ( " hard_timeout " , " 2 " , PHP_INI_SYSTEM , OnUpdateLong , hard_timeout , zend_executor_globals , executor_globals )
2011-09-13 18:38:12 +08:00
# ifdef PHP_WIN32
2011-11-24 20:46:45 +08:00
STD_PHP_INI_BOOLEAN ( " windows.show_crt_warning " , " 0 " , PHP_INI_ALL , OnUpdateBool , windows_show_crt_warning , php_core_globals , core_globals )
2011-09-13 18:38:12 +08:00
# endif
2017-08-23 06:34:06 +08:00
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 )
2017-08-12 02:30:50 +08:00
STD_PHP_INI_ENTRY ( " syslog.filter " , " no-ctrl " , PHP_INI_ALL , OnSetLogFilter , syslog_filter , php_core_globals , core_globals )
1999-04-10 03:09:29 +08:00
PHP_INI_END ( )
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-10 03:09:29 +08:00
2003-09-02 20:12:05 +08:00
/* True globals (no need for thread safety */
/* But don't make them a single int bitfield */
1999-04-24 06:45:01 +08:00
static int module_initialized = 0 ;
2003-09-02 20:12:05 +08:00
static int module_startup = 1 ;
static int module_shutdown = 0 ;
1999-04-24 06:45:01 +08:00
2009-07-08 00:42:11 +08:00
/* {{{ 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 ;
}
/* }}} */
2011-06-24 19:19:34 +08:00
/* {{{ php_get_module_initialized
*/
PHPAPI int php_get_module_initialized ( void )
{
return module_initialized ;
}
2012-09-21 02:24:55 +08:00
/* }}} */
2011-06-24 19:19:34 +08:00
2016-04-06 19:14:41 +08:00
/* {{{ php_log_err_with_severity
2001-06-06 21:06:12 +08:00
*/
2016-04-06 19:14:41 +08:00
PHPAPI ZEND_COLD void php_log_err_with_severity ( char * log_message , int syslog_type_int )
1999-04-08 05:05:13 +08:00
{
2007-04-06 21:58:48 +08:00
int fd = - 1 ;
1999-12-16 01:37:05 +08:00
time_t error_time ;
1999-04-08 05:05:13 +08:00
2009-10-05 21:56:49 +08:00
if ( PG ( in_error_log ) ) {
/* prevent recursive invocation */
return ;
}
PG ( in_error_log ) = 1 ;
1999-04-08 05:05:13 +08:00
/* Try to use the specified logging location. */
1999-04-11 00:25:23 +08:00
if ( PG ( error_log ) ! = NULL ) {
2000-05-29 00:22:28 +08:00
# ifdef HAVE_SYSLOG_H
1999-07-30 21:17:29 +08:00
if ( ! strcmp ( PG ( error_log ) , " syslog " ) ) {
2015-12-29 18:18:41 +08:00
php_syslog ( syslog_type_int , " %s " , log_message ) ;
2009-10-05 21:56:49 +08:00
PG ( in_error_log ) = 0 ;
1999-04-08 05:05:13 +08:00
return ;
}
# endif
2007-04-06 21:58:48 +08:00
fd = VCWD_OPEN_MODE ( PG ( error_log ) , O_CREAT | O_APPEND | O_WRONLY , 0644 ) ;
if ( fd ! = - 1 ) {
char * tmp ;
2014-10-27 19:21:00 +08:00
size_t len ;
2014-03-07 22:23:57 +08:00
zend_string * error_time_str ;
2009-05-04 03:08:49 +08:00
2000-02-10 23:55:10 +08:00
time ( & error_time ) ;
2012-09-23 22:59:31 +08:00
# ifdef ZTS
if ( ! php_during_module_startup ( ) ) {
2014-12-14 06:06:14 +08:00
error_time_str = php_format_date ( " d-M-Y H:i:s e " , 13 , error_time , 1 ) ;
2012-09-23 22:59:31 +08:00
} else {
2014-12-14 06:06:14 +08:00
error_time_str = php_format_date ( " d-M-Y H:i:s e " , 13 , error_time , 0 ) ;
2012-09-23 22:59:31 +08:00
}
# else
2014-12-14 06:06:14 +08:00
error_time_str = php_format_date ( " d-M-Y H:i:s e " , 13 , error_time , 1 ) ;
2012-09-23 22:59:31 +08:00
# endif
2015-06-30 18:59:27 +08:00
len = spprintf ( & tmp , 0 , " [%s] %s%s " , ZSTR_VAL ( error_time_str ) , log_message , PHP_EOL ) ;
2007-04-18 17:38:59 +08:00
# ifdef PHP_WIN32
php_flock ( fd , 2 ) ;
2014-10-27 19:21:00 +08:00
/* XXX should eventually write in a loop if len > UINT_MAX */
php_ignore_value ( write ( fd , tmp , ( unsigned ) len ) ) ;
# else
2011-05-17 00:58:02 +08:00
php_ignore_value ( write ( fd , tmp , len ) ) ;
2014-10-27 19:21:00 +08:00
# endif
2007-04-18 17:38:59 +08:00
efree ( tmp ) ;
2014-08-26 01:24:55 +08:00
zend_string_free ( error_time_str ) ;
2007-04-06 21:58:48 +08:00
close ( fd ) ;
2009-10-05 21:56:49 +08:00
PG ( in_error_log ) = 0 ;
2000-02-10 23:55:10 +08:00
return ;
}
1999-04-08 05:05:13 +08:00
}
2000-02-10 23:55:10 +08:00
/* Otherwise fall back to the default logging location, if we have one */
if ( sapi_module . log_message ) {
2016-07-04 16:46:44 +08:00
sapi_module . log_message ( log_message , syslog_type_int ) ;
1999-04-08 05:05:13 +08:00
}
2009-10-05 21:56:49 +08:00
PG ( in_error_log ) = 0 ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_write
wrapper for modules to use PHPWRITE */
2014-12-14 06:06:14 +08:00
PHPAPI size_t php_write ( void * buf , size_t size )
1999-04-08 05:05:13 +08:00
{
return PHPWRITE ( buf , size ) ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_printf
*/
2014-08-26 02:22:49 +08:00
PHPAPI size_t php_printf ( const char * format , . . . )
1999-04-08 05:05:13 +08:00
{
va_list args ;
2014-08-26 02:22:49 +08:00
size_t ret ;
2002-06-23 08:57:01 +08:00
char * buffer ;
2014-08-26 02:22:49 +08:00
size_t size ;
1999-04-08 05:05:13 +08:00
va_start ( args , format ) ;
2002-06-23 08:57:01 +08:00
size = vspprintf ( & buffer , 0 , format , args ) ;
2004-05-28 22:14:26 +08:00
ret = PHPWRITE ( buffer , size ) ;
efree ( buffer ) ;
1999-04-08 05:05:13 +08:00
va_end ( args ) ;
2007-07-15 23:21:12 +08:00
1999-04-08 05:05:13 +08:00
return ret ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2002-08-08 02:29:36 +08:00
/* {{{ php_verror */
2002-08-20 02:40:28 +08:00
/* php_verror is called from php_error_docref<n> functions.
* Its purpose is to unify error messages and automatically generate clickable
2019-07-16 00:15:17 +08:00
* html error messages if corresponding ini setting ( html_errors ) is activated .
2019-05-19 03:39:19 +08:00
* See : CODING_STANDARDS . md for details .
2002-08-20 02:40:28 +08:00
*/
2015-08-24 23:07:59 +08:00
PHPAPI ZEND_COLD void php_verror ( const char * docref , const char * params , int type , const char * format , va_list args )
2002-08-08 02:29:36 +08:00
{
2014-02-13 21:54:23 +08:00
zend_string * replace_buffer = NULL , * replace_origin = NULL ;
2003-12-12 15:59:46 +08:00
char * buffer = NULL , * docref_buf = NULL , * target = NULL ;
2002-08-10 05:57:03 +08:00
char * docref_target = " " , * docref_root = " " ;
2003-09-02 06:55:40 +08:00
char * p ;
2002-11-10 10:48:22 +08:00
int buffer_len = 0 ;
2011-09-13 21:29:35 +08:00
const char * space = " " ;
const char * class_name = " " ;
const char * function ;
2005-12-06 11:09:24 +08:00
int origin_len ;
2003-09-02 07:32:28 +08:00
char * origin ;
char * message ;
2010-03-12 18:28:59 +08:00
int is_function = 0 ;
2003-09-02 06:55:40 +08:00
2003-09-02 20:12:05 +08:00
/* get error text into buffer and escape for html if necessary */
2014-10-27 19:21:00 +08:00
buffer_len = ( int ) vspprintf ( & buffer , 0 , format , args ) ;
2010-11-17 22:09:46 +08:00
2003-09-02 20:12:05 +08:00
if ( PG ( html_errors ) ) {
2017-09-21 07:02:52 +08:00
replace_buffer = php_escape_html_entities ( ( unsigned char * ) buffer , buffer_len , 0 , ENT_COMPAT , get_safe_charset_hint ( ) ) ;
2016-01-06 01:53:04 +08:00
/* Retry with substituting invalid chars on fail. */
2016-01-06 03:03:05 +08:00
if ( ! replace_buffer | | ZSTR_LEN ( replace_buffer ) < 1 ) {
2017-09-21 07:02:52 +08:00
replace_buffer = php_escape_html_entities ( ( unsigned char * ) buffer , buffer_len , 0 , ENT_COMPAT | ENT_HTML_SUBSTITUTE_ERRORS , get_safe_charset_hint ( ) ) ;
2016-01-06 01:53:04 +08:00
}
2003-09-02 07:32:28 +08:00
efree ( buffer ) ;
2016-01-06 01:53:04 +08:00
if ( replace_buffer ) {
buffer = ZSTR_VAL ( replace_buffer ) ;
buffer_len = ( int ) ZSTR_LEN ( replace_buffer ) ;
} else {
buffer = " " ;
buffer_len = 0 ;
}
2003-09-02 07:32:28 +08:00
}
2003-09-02 20:12:05 +08:00
/* which function caused the problem if any at all */
if ( php_during_module_startup ( ) ) {
2010-03-12 18:28:59 +08:00
function = " PHP Startup " ;
2003-09-02 20:12:05 +08:00
} else if ( php_during_module_shutdown ( ) ) {
2010-03-12 18:28:59 +08:00
function = " PHP Shutdown " ;
2005-11-15 19:13:43 +08:00
} else if ( EG ( current_execute_data ) & &
2014-07-07 19:50:44 +08:00
EG ( current_execute_data ) - > func & &
ZEND_USER_CODE ( EG ( current_execute_data ) - > func - > common . type ) & &
2007-07-15 23:21:12 +08:00
EG ( current_execute_data ) - > opline & &
EG ( current_execute_data ) - > opline - > opcode = = ZEND_INCLUDE_OR_EVAL
) {
2010-04-20 18:57:45 +08:00
switch ( EG ( current_execute_data ) - > opline - > extended_value ) {
2005-11-15 19:13:43 +08:00
case ZEND_EVAL :
function = " eval " ;
2010-03-12 18:28:59 +08:00
is_function = 1 ;
2005-11-15 19:13:43 +08:00
break ;
case ZEND_INCLUDE :
function = " include " ;
2010-03-12 18:28:59 +08:00
is_function = 1 ;
2005-11-15 19:13:43 +08:00
break ;
case ZEND_INCLUDE_ONCE :
function = " include_once " ;
2010-03-12 18:28:59 +08:00
is_function = 1 ;
2005-11-15 19:13:43 +08:00
break ;
case ZEND_REQUIRE :
function = " require " ;
2010-03-12 18:28:59 +08:00
is_function = 1 ;
2005-11-15 19:13:43 +08:00
break ;
case ZEND_REQUIRE_ONCE :
function = " require_once " ;
2010-03-12 18:28:59 +08:00
is_function = 1 ;
2005-11-15 19:13:43 +08:00
break ;
default :
2010-03-12 18:28:59 +08:00
function = " Unknown " ;
2005-11-15 19:13:43 +08:00
}
2003-09-02 20:12:05 +08:00
} else {
2014-12-14 06:06:14 +08:00
function = get_active_function_name ( ) ;
2003-09-02 07:32:28 +08:00
if ( ! function | | ! strlen ( function ) ) {
2010-03-12 18:28:59 +08:00
function = " Unknown " ;
2003-09-02 07:32:28 +08:00
} else {
2010-03-12 18:28:59 +08:00
is_function = 1 ;
2014-12-14 06:06:14 +08:00
class_name = get_active_class_name ( & space ) ;
2003-03-08 23:20:12 +08:00
}
2003-09-02 07:32:28 +08:00
}
2003-03-08 23:20:12 +08:00
2003-09-02 20:12:05 +08:00
/* if we still have memory then format the origin */
2010-03-12 18:28:59 +08:00
if ( is_function ) {
2014-10-27 19:21:00 +08:00
origin_len = ( int ) spprintf ( & origin , 0 , " %s%s%s(%s) " , class_name , space , function , params ) ;
2003-09-02 20:12:05 +08:00
} else {
2014-10-27 19:21:00 +08:00
origin_len = ( int ) spprintf ( & origin , 0 , " %s " , function ) ;
2005-12-06 11:09:24 +08:00
}
if ( PG ( html_errors ) ) {
2017-09-21 07:02:52 +08:00
replace_origin = php_escape_html_entities ( ( unsigned char * ) origin , origin_len , 0 , ENT_COMPAT , get_safe_charset_hint ( ) ) ;
2005-12-06 11:09:24 +08:00
efree ( origin ) ;
2015-06-30 18:59:27 +08:00
origin = ZSTR_VAL ( replace_origin ) ;
2003-09-02 20:12:05 +08:00
}
/* origin and buffer available, so lets come up with the error message */
if ( docref & & docref [ 0 ] = = ' # ' ) {
docref_target = strchr ( docref , ' # ' ) ;
docref = NULL ;
}
2003-12-12 15:59:46 +08:00
/* no docref given but function is known (the default) */
2010-03-12 18:28:59 +08:00
if ( ! docref & & is_function ) {
2007-12-29 10:21:57 +08:00
int doclen ;
2013-06-26 03:26:26 +08:00
while ( * function = = ' _ ' ) {
function + + ;
}
2006-04-12 20:49:39 +08:00
if ( space [ 0 ] = = ' \0 ' ) {
2014-10-27 19:21:00 +08:00
doclen = ( int ) spprintf ( & docref_buf , 0 , " function.%s " , function ) ;
2006-04-12 20:49:39 +08:00
} else {
2014-10-27 19:21:00 +08:00
doclen = ( int ) spprintf ( & docref_buf , 0 , " %s.%s " , class_name , function ) ;
2006-04-12 20:49:39 +08:00
}
2003-09-02 20:12:05 +08:00
while ( ( p = strchr ( docref_buf , ' _ ' ) ) ! = NULL ) {
* p = ' - ' ;
2002-08-13 17:37:51 +08:00
}
2007-12-29 10:21:57 +08:00
docref = php_strtolower ( docref_buf , doclen ) ;
2003-09-02 20:12:05 +08:00
}
2003-12-12 15:59:46 +08:00
/* we have a docref for a function AND
2011-08-11 00:31:29 +08:00
* - we show errors in html mode AND
* - the user wants to see the links
2003-12-12 15:59:46 +08:00
*/
2011-08-11 00:31:29 +08:00
if ( docref & & is_function & & PG ( html_errors ) & & strlen ( PG ( docref_root ) ) ) {
2003-09-02 20:12:05 +08:00
if ( strncmp ( docref , " http:// " , 7 ) ) {
2003-12-12 15:59:46 +08:00
/* We don't have 'http://' so we use docref_root */
char * ref ; /* temp copy for duplicated docref */
2003-09-02 20:12:05 +08:00
docref_root = PG ( docref_root ) ;
2003-12-12 15:59:46 +08:00
2003-09-02 20:12:05 +08:00
ref = estrdup ( docref ) ;
if ( docref_buf ) {
efree ( docref_buf ) ;
2002-08-09 03:12:27 +08:00
}
2003-09-02 20:12:05 +08:00
docref_buf = ref ;
2003-12-12 15:59:46 +08:00
/* strip of the target if any */
2003-09-02 20:12:05 +08:00
p = strrchr ( ref , ' # ' ) ;
if ( p ) {
target = estrdup ( p ) ;
if ( target ) {
docref_target = target ;
* p = ' \0 ' ;
2002-08-10 05:57:03 +08:00
}
}
2003-12-12 15:59:46 +08:00
/* add the extension if it is set in ini */
if ( PG ( docref_ext ) & & strlen ( PG ( docref_ext ) ) ) {
2003-09-02 20:12:05 +08:00
spprintf ( & docref_buf , 0 , " %s%s " , ref , PG ( docref_ext ) ) ;
efree ( ref ) ;
2002-11-10 10:48:22 +08:00
}
2003-12-12 15:59:46 +08:00
docref = docref_buf ;
2003-09-02 07:32:28 +08:00
}
2003-12-12 15:59:46 +08:00
/* display html formatted or only show the additional links */
2003-09-02 20:12:05 +08:00
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 ) ;
2002-08-09 03:12:27 +08:00
}
2003-09-02 20:12:05 +08:00
if ( target ) {
efree ( target ) ;
2002-11-10 10:48:22 +08:00
}
2002-08-08 02:29:36 +08:00
} else {
2003-09-04 22:43:36 +08:00
spprintf ( & message , 0 , " %s: %s " , origin , buffer ) ;
2003-09-02 20:12:05 +08:00
}
2014-02-13 21:54:23 +08:00
if ( replace_origin ) {
2014-08-26 01:24:55 +08:00
zend_string_free ( replace_origin ) ;
2014-02-13 21:54:23 +08:00
} else {
efree ( origin ) ;
}
2003-09-02 20:12:05 +08:00
if ( docref_buf ) {
efree ( docref_buf ) ;
}
2014-02-13 21:54:23 +08:00
if ( replace_buffer ) {
2014-08-26 01:24:55 +08:00
zend_string_free ( replace_buffer ) ;
2014-02-13 21:54:23 +08:00
} else {
2016-01-06 01:53:04 +08:00
if ( buffer_len > 0 ) {
efree ( buffer ) ;
}
2014-02-13 21:54:23 +08:00
}
2006-09-18 11:29:21 +08:00
php_error ( type , " %s " , message ) ;
efree ( message ) ;
2002-08-08 02:29:36 +08:00
}
/* }}} */
2019-07-13 08:05:17 +08:00
/* {{{ php_error_docref */
/* Generate an error which links to docref or the php.net documentation if docref is NULL */
PHPAPI ZEND_COLD void php_error_docref ( const char * docref , int type , const char * format , . . . )
2002-08-08 02:29:36 +08:00
{
va_list args ;
2007-07-15 23:21:12 +08:00
2002-08-08 02:29:36 +08:00
va_start ( args , format ) ;
2014-12-14 06:06:14 +08:00
php_verror ( docref , " " , type , format , args ) ;
2002-08-08 02:29:36 +08:00
va_end ( args ) ;
}
/* }}} */
2002-08-09 03:12:27 +08:00
/* {{{ php_error_docref1 */
2019-05-19 03:39:19 +08:00
/* See: CODING_STANDARDS.md for details. */
2015-08-24 23:07:59 +08:00
PHPAPI ZEND_COLD void php_error_docref1 ( const char * docref , const char * param1 , int type , const char * format , . . . )
2002-08-08 02:29:36 +08:00
{
va_list args ;
2007-07-15 23:21:12 +08:00
2002-08-08 02:29:36 +08:00
va_start ( args , format ) ;
2014-12-14 06:06:14 +08:00
php_verror ( docref , param1 , type , format , args ) ;
2002-08-08 02:29:36 +08:00
va_end ( args ) ;
}
/* }}} */
2002-08-09 03:12:27 +08:00
/* {{{ php_error_docref2 */
2019-05-19 03:39:19 +08:00
/* See: CODING_STANDARDS.md for details. */
2015-08-24 23:07:59 +08:00
PHPAPI ZEND_COLD void php_error_docref2 ( const char * docref , const char * param1 , const char * param2 , int type , const char * format , . . . )
2002-08-08 02:29:36 +08:00
{
2002-08-09 03:12:27 +08:00
char * params ;
2002-08-08 02:29:36 +08:00
va_list args ;
2007-07-15 23:21:12 +08:00
2002-08-09 03:12:27 +08:00
spprintf ( & params , 0 , " %s,%s " , param1 , param2 ) ;
2002-08-08 02:29:36 +08:00
va_start ( args , format ) ;
2014-12-14 06:06:14 +08:00
php_verror ( docref , params ? params : " ... " , type , format , args ) ;
2002-08-08 02:29:36 +08:00
va_end ( args ) ;
2003-09-02 06:55:40 +08:00
if ( params ) {
2002-08-09 03:12:27 +08:00
efree ( params ) ;
2003-09-02 06:55:40 +08:00
}
2002-08-08 02:29:36 +08:00
}
/* }}} */
2010-01-27 04:04:03 +08:00
# ifdef PHP_WIN32
2015-08-24 23:07:59 +08:00
PHPAPI ZEND_COLD void php_win32_docref2_from_error ( DWORD error , const char * param1 , const char * param2 ) {
2018-09-17 15:48:33 +08:00
char * buf = php_win32_error_to_msg ( error ) ;
size_t buf_len ;
buf_len = strlen ( buf ) ;
if ( buf_len > = 2 ) {
buf [ buf_len - 1 ] = ' \0 ' ;
buf [ buf_len - 2 ] = ' \0 ' ;
2010-01-27 04:04:03 +08:00
}
2018-09-17 15:48:33 +08:00
php_error_docref2 ( NULL , param1 , param2 , E_WARNING , " %s (code: %lu) " , buf , error ) ;
php_win32_error_msg_free ( buf ) ;
2010-01-27 04:04:03 +08:00
}
# endif
2002-05-11 20:41:33 +08:00
/* {{{ php_html_puts */
2014-12-14 06:06:14 +08:00
PHPAPI void php_html_puts ( const char * str , size_t size )
2002-03-05 02:46:55 +08:00
{
2014-12-14 06:06:14 +08:00
zend_html_puts ( str , size ) ;
2002-03-05 02:46:55 +08:00
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_error_cb
extended error handling function */
2016-11-26 22:18:42 +08:00
static ZEND_COLD void php_error_cb ( int type , const char * error_filename , const uint32_t error_lineno , const char * format , va_list args )
1999-04-08 05:05:13 +08:00
{
2002-04-10 09:27:44 +08:00
char * buffer ;
2002-04-07 02:49:59 +08:00
int buffer_len , display ;
1999-04-08 05:05:13 +08:00
2014-10-27 19:21:00 +08:00
buffer_len = ( int ) vspprintf ( & buffer , PG ( log_errors_max_len ) , format , args ) ;
2003-05-07 09:02:23 +08:00
/* 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 )
2002-04-07 02:49:59 +08:00
| | ( ! PG ( ignore_repeated_source )
2006-02-26 18:57:00 +08:00
& & ( ( PG ( last_error_lineno ) ! = ( int ) error_lineno )
2003-05-07 09:02:23 +08:00
| | strcmp ( PG ( last_error_file ) , error_filename ) ) ) ) {
2002-04-07 02:49:59 +08:00
display = 1 ;
} else {
display = 0 ;
}
} else {
display = 1 ;
}
2003-05-07 09:02:23 +08:00
2017-12-23 20:25:26 +08:00
/* according to error handling mode, throw exception or show it */
if ( EG ( error_handling ) = = EH_THROW ) {
2003-05-07 09:02:23 +08:00
switch ( type ) {
2006-05-11 15:56:36 +08:00
case E_ERROR :
2003-05-07 09:02:23 +08:00
case E_CORE_ERROR :
case E_COMPILE_ERROR :
2006-05-11 15:56:36 +08:00
case E_USER_ERROR :
2003-05-07 09:02:23 +08:00
case E_PARSE :
/* fatal errors are real errors and cannot be made exceptions */
break ;
2005-08-17 02:10:34 +08:00
case E_STRICT :
2008-02-24 01:06:22 +08:00
case E_DEPRECATED :
2008-07-21 17:41:00 +08:00
case E_USER_DEPRECATED :
2005-08-17 02:10:34 +08:00
/* for the sake of BC to old damaged code */
break ;
2005-03-23 15:54:22 +08:00
case E_NOTICE :
case E_USER_NOTICE :
2005-03-24 09:11:11 +08:00
/* notices are no errors and are not treated as such like E_WARNINGS */
2005-03-23 15:54:22 +08:00
break ;
2003-05-07 09:02:23 +08:00
default :
/* throw an exception if we are in EH_THROW mode
2005-03-24 09:11:11 +08:00
* but DO NOT overwrite a pending exception
2003-05-07 09:02:23 +08:00
*/
2017-12-23 20:25:26 +08:00
if ( ! EG ( exception ) ) {
2014-12-14 06:06:14 +08:00
zend_throw_error_exception ( EG ( exception_class ) , buffer , 0 , type ) ;
2003-05-07 09:02:23 +08:00
}
2003-08-26 04:51:40 +08:00
efree ( buffer ) ;
2003-05-07 09:02:23 +08:00
return ;
}
}
2000-09-01 20:06:52 +08:00
2017-12-23 20:34:17 +08:00
/* 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 ;
}
2000-09-01 20:06:52 +08:00
/* display/log the error if necessary */
2002-04-07 02:49:59 +08:00
if ( display & & ( EG ( error_reporting ) & type | | ( type & E_CORE ) )
2000-09-01 20:06:52 +08:00
& & ( PG ( log_errors ) | | PG ( display_errors ) | | ( ! module_initialized ) ) ) {
1999-04-08 05:05:13 +08:00
char * error_type_str ;
2015-12-29 18:18:41 +08:00
int syslog_type_int = LOG_NOTICE ;
1999-04-08 05:05:13 +08:00
switch ( type ) {
case E_ERROR :
case E_CORE_ERROR :
case E_COMPILE_ERROR :
2000-04-19 23:10:14 +08:00
case E_USER_ERROR :
1999-04-08 05:05:13 +08:00
error_type_str = " Fatal error " ;
2015-12-29 18:18:41 +08:00
syslog_type_int = LOG_ERR ;
1999-04-08 05:05:13 +08:00
break ;
2006-05-10 22:04:18 +08:00
case E_RECOVERABLE_ERROR :
2016-09-03 19:05:37 +08:00
error_type_str = " Recoverable fatal error " ;
2015-12-29 18:18:41 +08:00
syslog_type_int = LOG_ERR ;
2006-05-10 22:04:18 +08:00
break ;
1999-04-08 05:05:13 +08:00
case E_WARNING :
case E_CORE_WARNING :
case E_COMPILE_WARNING :
2000-04-19 23:10:14 +08:00
case E_USER_WARNING :
1999-04-08 05:05:13 +08:00
error_type_str = " Warning " ;
2015-12-29 18:18:41 +08:00
syslog_type_int = LOG_WARNING ;
1999-04-08 05:05:13 +08:00
break ;
case E_PARSE :
error_type_str = " Parse error " ;
2015-12-29 18:18:41 +08:00
syslog_type_int = LOG_EMERG ;
1999-04-08 05:05:13 +08:00
break ;
case E_NOTICE :
2000-04-19 23:10:14 +08:00
case E_USER_NOTICE :
error_type_str = " Notice " ;
2015-12-29 18:18:41 +08:00
syslog_type_int = LOG_NOTICE ;
2000-04-19 23:10:14 +08:00
break ;
2003-11-19 14:11:47 +08:00
case E_STRICT :
error_type_str = " Strict Standards " ;
2015-12-29 18:18:41 +08:00
syslog_type_int = LOG_INFO ;
2003-11-19 14:11:47 +08:00
break ;
2008-02-24 01:06:22 +08:00
case E_DEPRECATED :
2008-07-21 17:41:00 +08:00
case E_USER_DEPRECATED :
2008-02-24 01:06:22 +08:00
error_type_str = " Deprecated " ;
2015-12-29 18:18:41 +08:00
syslog_type_int = LOG_INFO ;
2008-02-24 01:06:22 +08:00
break ;
1999-04-08 05:05:13 +08:00
default :
error_type_str = " Unknown error " ;
break ;
}
2000-09-01 20:06:52 +08:00
if ( ! module_initialized | | PG ( log_errors ) ) {
2002-04-10 09:27:44 +08:00
char * log_buffer ;
2000-06-13 04:22:17 +08:00
# ifdef PHP_WIN32
2014-12-03 23:33:05 +08:00
if ( type = = E_CORE_ERROR | | type = = E_CORE_WARNING ) {
syslog ( LOG_ALERT , " PHP %s: %s (%s) " , error_type_str , buffer , GetCommandLine ( ) ) ;
2000-09-01 20:06:52 +08:00
}
2000-06-13 04:22:17 +08:00
# endif
2017-11-22 05:50:27 +08:00
spprintf ( & log_buffer , 0 , " PHP %s: %s in %s on line % " PRIu32 , error_type_str , buffer , error_filename , error_lineno ) ;
2016-04-06 19:14:41 +08:00
php_log_err_with_severity ( log_buffer , syslog_type_int ) ;
2002-04-10 09:27:44 +08:00
efree ( log_buffer ) ;
2000-09-01 20:06:52 +08:00
}
2010-03-12 18:28:59 +08:00
2010-05-31 18:29:43 +08:00
if ( PG ( display_errors ) & & ( ( module_initialized & & ! PG ( during_request_startup ) ) | | ( PG ( display_startup_errors ) ) ) ) {
2001-07-10 23:59:33 +08:00
if ( PG ( xmlrpc_errors ) ) {
2017-11-22 05:50:27 +08:00
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 ) ;
2003-03-30 21:59:05 +08:00
} else {
char * prepend_string = INI_STR ( " error_prepend_string " ) ;
char * append_string = INI_STR ( " error_append_string " ) ;
2005-12-06 11:09:24 +08:00
if ( PG ( html_errors ) ) {
2011-06-24 07:00:53 +08:00
if ( type = = E_ERROR | | type = = E_PARSE ) {
2017-09-21 07:02:52 +08:00
zend_string * buf = php_escape_html_entities ( ( unsigned char * ) buffer , buffer_len , 0 , ENT_COMPAT , get_safe_charset_hint ( ) ) ;
2017-11-22 05:50:27 +08:00
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 ) ) ;
2014-08-26 01:24:55 +08:00
zend_string_free ( buf ) ;
2005-12-07 10:37:05 +08:00
} else {
2017-11-22 05:50:27 +08:00
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 ) ) ;
2005-12-07 10:37:05 +08:00
}
2005-12-06 11:09:24 +08:00
} else {
2007-07-24 22:21:36 +08:00
/* Write CLI/CGI errors to stderr if display_errors = "stderr" */
2018-07-09 10:18:20 +08:00
if ( ( ! strcmp ( sapi_module . name , " cli " ) | | ! strcmp ( sapi_module . name , " cgi " ) | | ! strcmp ( sapi_module . name , " phpdbg " ) ) & &
2007-07-24 22:21:36 +08:00
PG ( display_errors ) = = PHP_DISPLAY_ERRORS_STDERR
) {
2017-11-22 05:50:27 +08:00
fprintf ( stderr , " %s: %s in %s on line % " PRIu32 " \n " , error_type_str , buffer , error_filename , error_lineno ) ;
2016-12-28 05:44:46 +08:00
# ifdef PHP_WIN32
2010-01-24 20:39:31 +08:00
fflush ( stderr ) ;
# endif
2007-07-24 22:21:36 +08:00
} else {
2017-11-22 05:50:27 +08:00
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 ) ) ;
2007-07-24 22:21:36 +08:00
}
2005-12-06 11:09:24 +08:00
}
1999-04-08 05:05:13 +08:00
}
2000-09-01 20:06:52 +08:00
}
2000-06-03 11:05:29 +08:00
# if ZEND_DEBUG
2002-11-21 22:56:06 +08:00
if ( PG ( report_zend_debug ) ) {
2000-09-01 20:06:52 +08:00
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 ;
2000-06-03 11:05:29 +08:00
}
2017-11-22 05:50:27 +08:00
zend_output_debug_string ( trigger_break , " %s(% " PRIu32 " ) : %s - %s " , error_filename , error_lineno , error_type_str , buffer ) ;
1999-04-08 05:05:13 +08:00
}
2000-09-01 20:06:52 +08:00
# endif
1999-04-08 05:05:13 +08:00
}
2000-01-15 21:02:54 +08:00
2000-09-01 20:06:52 +08:00
/* Bail out if we can't recover */
2000-01-15 21:02:54 +08:00
switch ( type ) {
case E_CORE_ERROR :
2000-07-03 00:36:31 +08:00
if ( ! module_initialized ) {
/* bad error in module startup - no way we can live with this */
exit ( - 2 ) ;
}
/* no break - intentionally */
case E_ERROR :
2006-05-10 22:04:18 +08:00
case E_RECOVERABLE_ERROR :
2007-06-15 17:20:27 +08:00
case E_PARSE :
2000-01-15 21:02:54 +08:00
case E_COMPILE_ERROR :
2000-04-19 23:10:14 +08:00
case E_USER_ERROR :
2015-03-09 21:08:01 +08:00
EG ( exit_status ) = 255 ;
2000-01-15 21:02:54 +08:00
if ( module_initialized ) {
2007-10-18 21:11:46 +08:00
if ( ! PG ( display_errors ) & &
! SG ( headers_sent ) & &
2015-03-09 21:08:01 +08:00
SG ( sapi_headers ) . http_response_code = = 200
2007-07-15 23:21:12 +08:00
) {
2007-06-15 17:20:27 +08:00
sapi_header_line ctr = { 0 } ;
2007-07-15 23:21:12 +08:00
2007-06-15 17:20:27 +08:00
ctr . line = " HTTP/1.0 500 Internal Server Error " ;
2010-07-14 23:20:44 +08:00
ctr . line_len = sizeof ( " HTTP/1.0 500 Internal Server Error " ) - 1 ;
2014-12-14 06:06:14 +08:00
sapi_header_op ( SAPI_HEADER_REPLACE , & ctr ) ;
2007-06-15 17:20:27 +08:00
}
/* the parser would return 1 (failure), we can bail out nicely */
2017-09-24 14:53:27 +08:00
if ( type ! = E_PARSE ) {
2007-06-15 17:20:27 +08:00
/* restore memory limit */
2014-12-14 06:06:14 +08:00
zend_set_memory_limit ( PG ( memory_limit ) ) ;
2007-06-15 17:20:27 +08:00
efree ( buffer ) ;
2014-12-14 06:06:14 +08:00
zend_objects_store_mark_destructed ( & EG ( objects_store ) ) ;
2007-06-15 17:20:27 +08:00
zend_bailout ( ) ;
return ;
}
2000-01-15 21:02:54 +08:00
}
break ;
}
2000-09-01 20:06:52 +08:00
/* Log if necessary */
2002-04-10 09:27:44 +08:00
if ( ! display ) {
efree ( buffer ) ;
return ;
}
2010-03-12 18:28:59 +08:00
2002-04-10 09:27:44 +08:00
efree ( buffer ) ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2010-04-27 07:53:30 +08:00
/* {{{ php_get_current_user
*/
2014-12-14 06:06:14 +08:00
PHPAPI char * php_get_current_user ( void )
2010-04-27 07:53:30 +08:00
{
2014-08-26 02:22:49 +08:00
zend_stat_t * pstat ;
2010-04-27 07:53:30 +08:00
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 */
2014-12-14 06:06:14 +08:00
pstat = sapi_get_stat ( ) ;
2010-04-27 07:53:30 +08:00
if ( ! pstat ) {
return " " ;
} else {
# ifdef PHP_WIN32
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
char * name = php_win32_get_username ( ) ;
int len ;
2010-04-27 07:53:30 +08:00
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
if ( ! name ) {
2010-04-27 07:53:30 +08:00
return " " ;
}
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
len = ( int ) strlen ( name ) ;
2010-04-27 07:53:30 +08:00
name [ len ] = ' \0 ' ;
SG ( request_info ) . current_user_length = len ;
SG ( request_info ) . current_user = estrndup ( name , len ) ;
Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it
https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx
The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:
https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672
Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.
The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it
https://msdn.microsoft.com/en-us/library/tsbaswba.aspx
However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.
For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.
This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).
In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.
The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).
The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.
Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.
Thanks.
2016-06-20 15:32:19 +08:00
free ( name ) ;
2013-01-02 12:14:44 +08:00
return SG ( request_info ) . current_user ;
2010-04-27 07:53:30 +08:00
# 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 " " ;
}
2015-02-27 12:00:52 +08:00
if ( retpwptr = = NULL ) {
efree ( pwbuf ) ;
return " " ;
}
2015-02-27 12:02:42 +08:00
pwd = & _pw ;
2010-04-27 07:53:30 +08:00
# 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
2013-01-02 12:14:44 +08:00
return SG ( request_info ) . current_user ;
2010-04-27 07:53:30 +08:00
# endif
2013-01-02 12:14:44 +08:00
}
2010-04-27 07:53:30 +08:00
}
/* }}} */
2002-07-17 16:06:43 +08:00
/* {{{ proto bool set_time_limit(int seconds)
2000-05-18 03:45:46 +08:00
Sets the maximum time a script can run */
1999-07-25 06:16:54 +08:00
PHP_FUNCTION ( set_time_limit )
1999-04-08 05:05:13 +08:00
{
2014-08-26 01:24:55 +08:00
zend_long new_timeout ;
2008-07-25 21:46:56 +08:00
char * new_timeout_str ;
int new_timeout_strlen ;
2014-02-10 14:04:30 +08:00
zend_string * key ;
1999-04-08 05:05:13 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) , " l " , & new_timeout ) = = FAILURE ) {
2008-06-21 10:41:27 +08:00
return ;
1999-04-08 05:05:13 +08:00
}
2013-01-02 12:14:44 +08:00
2014-10-27 19:21:00 +08:00
new_timeout_strlen = ( int ) zend_spprintf ( & new_timeout_str , 0 , ZEND_LONG_FMT , new_timeout ) ;
2000-06-11 18:27:36 +08:00
2014-08-26 01:24:55 +08:00
key = zend_string_init ( " max_execution_time " , sizeof ( " max_execution_time " ) - 1 , 0 ) ;
2014-12-14 06:06:14 +08:00
if ( zend_alter_ini_entry_chars_ex ( key , new_timeout_str , new_timeout_strlen , PHP_INI_USER , PHP_INI_STAGE_RUNTIME , 0 ) = = SUCCESS ) {
2008-07-25 21:46:56 +08:00
RETVAL_TRUE ;
2002-07-17 16:06:43 +08:00
} else {
2008-07-25 21:46:56 +08:00
RETVAL_FALSE ;
2002-07-17 16:06:43 +08:00
}
2018-05-28 21:27:12 +08:00
zend_string_release_ex ( key , 0 ) ;
2008-07-25 21:46:56 +08:00
efree ( new_timeout_str ) ;
1999-04-08 05:05:13 +08:00
}
2000-05-18 03:45:46 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_fopen_wrapper_for_zend
*/
2015-03-04 07:05:28 +08:00
static FILE * php_fopen_wrapper_for_zend ( const char * filename , zend_string * * opened_path )
1999-04-08 05:05:13 +08:00
{
2010-04-27 07:53:30 +08:00
return php_stream_open_wrapper_as_file ( ( char * ) filename , " rb " , USE_PATH | IGNORE_URL_WIN | REPORT_ERRORS | STREAM_OPEN_FOR_INCLUDE , opened_path ) ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2014-12-14 06:06:14 +08:00
static void php_zend_stream_closer ( void * handle ) /* { { { */
2003-02-18 17:37:54 +08:00
{
php_stream_close ( ( php_stream * ) handle ) ;
}
2007-07-15 23:34:28 +08:00
/* }}} */
2003-02-18 17:37:54 +08:00
2014-12-14 06:06:14 +08:00
static void php_zend_stream_mmap_closer ( void * handle ) /* { { { */
2005-06-05 00:16:53 +08:00
{
2008-03-17 05:06:55 +08:00
php_stream_mmap_unmap ( ( php_stream * ) handle ) ;
2014-12-14 06:06:14 +08:00
php_zend_stream_closer ( handle ) ;
2008-03-17 05:06:55 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
static size_t php_zend_stream_fsizer ( void * handle ) /* { { { */
2008-03-17 05:06:55 +08:00
{
php_stream_statbuf ssb ;
if ( php_stream_stat ( ( php_stream * ) handle , & ssb ) = = 0 ) {
return ssb . sb . st_size ;
}
return 0 ;
2005-06-05 00:16:53 +08:00
}
2007-07-15 23:34:28 +08:00
/* }}} */
2005-06-05 00:16:53 +08:00
2014-12-14 06:06:14 +08:00
static int php_stream_open_for_zend ( const char * filename , zend_file_handle * handle ) /* { { { */
2007-01-08 11:39:09 +08:00
{
2014-12-14 06:06:14 +08:00
return php_stream_open_for_zend_ex ( filename , handle , USE_PATH | REPORT_ERRORS | STREAM_OPEN_FOR_INCLUDE ) ;
2007-01-08 11:39:09 +08:00
}
2007-07-15 23:34:28 +08:00
/* }}} */
2007-01-08 11:39:09 +08:00
2014-12-14 06:06:14 +08:00
PHPAPI int php_stream_open_for_zend_ex ( const char * filename , zend_file_handle * handle , int mode ) /* { { { */
2003-02-18 17:37:54 +08:00
{
2008-03-17 05:06:55 +08:00
char * p ;
size_t len , mapped_len ;
php_stream * stream = php_stream_open_wrapper ( ( char * ) filename , " rb " , mode , & handle - > opened_path ) ;
2003-02-18 17:37:54 +08:00
if ( stream ) {
2012-01-17 17:30:12 +08:00
# if HAVE_MMAP || defined(PHP_WIN32)
2011-10-16 09:19:55 +08:00
size_t page_size = REAL_PAGE_SIZE ;
# endif
2003-02-18 17:37:54 +08:00
handle - > filename = ( char * ) filename ;
handle - > free_filename = 0 ;
2008-03-17 05:06:55 +08:00
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 ;
2013-03-03 23:44:46 +08:00
/* can we mmap immediately? */
2008-03-17 05:06:55 +08:00
memset ( & handle - > handle . stream . mmap , 0 , sizeof ( handle - > handle . stream . mmap ) ) ;
2014-12-14 06:06:14 +08:00
len = php_zend_stream_fsizer ( stream ) ;
2009-04-28 15:13:30 +08:00
if ( len ! = 0
2012-01-17 17:30:12 +08:00
# if HAVE_MMAP || defined(PHP_WIN32)
2011-10-16 09:19:55 +08:00
& & ( ( len - 1 ) % page_size ) < = page_size - ZEND_MMAP_AHEAD
# endif
2009-04-28 15:13:30 +08:00
& & php_stream_mmap_possible ( stream )
2008-03-17 05:55:46 +08:00
& & ( p = php_stream_mmap_range ( stream , 0 , len , PHP_STREAM_MAP_MODE_SHARED_READONLY , & mapped_len ) ) ! = NULL ) {
2008-03-17 05:06:55 +08:00
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 ;
}
2005-06-06 09:51:48 +08:00
/* suppress warning if this stream is not explicitly closed */
php_stream_auto_cleanup ( stream ) ;
2003-02-18 17:37:54 +08:00
return SUCCESS ;
}
return FAILURE ;
}
2007-07-15 23:34:28 +08:00
/* }}} */
2003-02-18 17:37:54 +08:00
2017-07-27 05:10:07 +08:00
static zend_string * php_resolve_path_for_zend ( const char * filename , size_t filename_len ) /* { { { */
2008-03-05 21:34:12 +08:00
{
2014-12-14 06:06:14 +08:00
return php_resolve_path ( filename , filename_len , PG ( include_path ) ) ;
2008-03-05 21:34:12 +08:00
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_get_configuration_directive_for_zend
*/
2014-09-02 00:57:33 +08:00
static zval * php_get_configuration_directive_for_zend ( zend_string * name )
1999-06-20 03:23:24 +08:00
{
2014-09-02 00:57:33 +08:00
return cfg_get_entry_ex ( name ) ;
1999-06-20 03:23:24 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-06-20 03:23:24 +08:00
2015-04-29 20:35:35 +08:00
/* {{{ php_free_request_globals
*/
static void php_free_request_globals ( void )
{
if ( PG ( last_error_message ) ) {
2015-05-13 14:43:05 +08:00
free ( PG ( last_error_message ) ) ;
2015-04-29 20:35:35 +08:00
PG ( last_error_message ) = NULL ;
}
if ( PG ( last_error_file ) ) {
2015-05-13 14:43:05 +08:00
free ( PG ( last_error_file ) ) ;
2015-04-29 20:35:35 +08:00
PG ( last_error_file ) = NULL ;
}
if ( PG ( php_sys_temp_dir ) ) {
efree ( PG ( php_sys_temp_dir ) ) ;
PG ( php_sys_temp_dir ) = NULL ;
}
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_message_handler_for_zend
*/
2015-08-24 23:07:59 +08:00
static ZEND_COLD void php_message_handler_for_zend ( zend_long message , const void * data )
1999-04-08 05:05:13 +08:00
{
switch ( message ) {
2003-08-21 07:00:08 +08:00
case ZMSG_FAILED_INCLUDE_FOPEN :
2014-12-14 06:06:14 +08:00
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 ) ) ) ;
1999-04-08 05:05:13 +08:00
break ;
2003-08-21 07:00:08 +08:00
case ZMSG_FAILED_REQUIRE_FOPEN :
2014-12-14 06:06:14 +08:00
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 ) ) ) ;
1999-04-08 05:05:13 +08:00
break ;
2003-08-21 07:00:08 +08:00
case ZMSG_FAILED_HIGHLIGHT_FOPEN :
2014-12-14 06:06:14 +08:00
php_error_docref ( NULL , E_WARNING , " Failed opening '%s' for highlighting " , php_strip_url_passwd ( ( char * ) data ) ) ;
1999-04-08 05:05:13 +08:00
break ;
1999-05-22 18:56:36 +08:00
case ZMSG_MEMORY_LEAK_DETECTED :
2003-08-21 07:00:08 +08:00
case ZMSG_MEMORY_LEAK_REPEATED :
2003-08-19 06:31:29 +08:00
# if ZEND_DEBUG
2004-02-11 02:46:53 +08:00
if ( EG ( error_reporting ) & E_WARNING ) {
2006-12-28 20:01:50 +08:00
char memory_leak_buf [ 1024 ] ;
1999-04-08 05:05:13 +08:00
2003-08-21 07:00:08 +08:00
if ( message = = ZMSG_MEMORY_LEAK_DETECTED ) {
2006-07-18 17:06:33 +08:00
zend_leak_info * t = ( zend_leak_info * ) data ;
1999-05-22 18:56:36 +08:00
2017-11-22 05:50:27 +08:00
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 ) ) ;
2003-08-21 07:00:08 +08:00
if ( t - > orig_filename ) {
char relay_buf [ 512 ] ;
1999-08-28 19:17:28 +08:00
2017-11-22 05:50:27 +08:00
snprintf ( relay_buf , 512 , " %s(% " PRIu32 " ) : Actual location (location was relayed) \n " , t - > orig_filename , t - > orig_lineno ) ;
2006-12-28 20:01:50 +08:00
strlcat ( memory_leak_buf , relay_buf , sizeof ( memory_leak_buf ) ) ;
1999-05-22 18:56:36 +08:00
}
2003-08-21 07:00:08 +08:00
} else {
2007-04-16 16:09:56 +08:00
unsigned long leak_count = ( zend_uintptr_t ) data ;
2003-08-21 07:00:08 +08:00
2017-11-22 05:50:27 +08:00
snprintf ( memory_leak_buf , 512 , " Last leak repeated %lu time%s \n " , leak_count , ( leak_count > 1 ? " s " : " " ) ) ;
2003-08-21 07:00:08 +08:00
}
2010-03-12 18:28:59 +08:00
# if defined(PHP_WIN32)
2018-09-08 19:57:01 +08:00
if ( IsDebuggerPresent ( ) ) {
OutputDebugString ( memory_leak_buf ) ;
} else {
fprintf ( stderr , " %s " , memory_leak_buf ) ;
}
2010-03-12 18:28:59 +08:00
# else
2003-08-21 07:00:08 +08:00
fprintf ( stderr , " %s " , memory_leak_buf ) ;
2010-03-12 18:28:59 +08:00
# endif
2003-08-19 11:25:00 +08:00
}
2003-08-21 07:00:08 +08:00
# endif
2003-08-19 06:31:29 +08:00
break ;
2003-08-21 07:00:08 +08:00
case ZMSG_MEMORY_LEAKS_GRAND_TOTAL :
2003-08-19 06:31:29 +08:00
# if ZEND_DEBUG
2004-02-11 02:46:53 +08:00
if ( EG ( error_reporting ) & E_WARNING ) {
2003-08-21 07:00:08 +08:00
char memory_leak_buf [ 512 ] ;
2003-08-19 06:31:29 +08:00
2014-08-26 01:28:33 +08:00
snprintf ( memory_leak_buf , 512 , " === Total %d memory leaks detected === \n " , * ( ( uint32_t * ) data ) ) ;
2010-03-12 18:28:59 +08:00
# if defined(PHP_WIN32)
2018-09-08 19:57:01 +08:00
if ( IsDebuggerPresent ( ) ) {
OutputDebugString ( memory_leak_buf ) ;
} else {
fprintf ( stderr , " %s " , memory_leak_buf ) ;
}
2010-03-12 18:28:59 +08:00
# else
2003-08-21 07:00:08 +08:00
fprintf ( stderr , " %s " , memory_leak_buf ) ;
2010-03-12 18:28:59 +08:00
# endif
2003-08-19 11:25:00 +08:00
}
2003-08-21 07:00:08 +08:00
# endif
1999-04-08 05:05:13 +08:00
break ;
1999-06-01 03:58:20 +08:00
case ZMSG_LOG_SCRIPT_NAME : {
1999-11-27 00:32:02 +08:00
struct tm * ta , tmbuf ;
1999-08-27 12:31:53 +08:00
time_t curtime ;
1999-11-27 00:32:02 +08:00
char * datetime_str , asctimebuf [ 52 ] ;
2006-11-23 16:37:21 +08:00
char memory_leak_buf [ 4096 ] ;
1999-06-01 03:58:20 +08:00
1999-08-27 12:31:53 +08:00
time ( & curtime ) ;
2000-05-04 18:38:17 +08:00
ta = php_localtime_r ( & curtime , & tmbuf ) ;
datetime_str = php_asctime_r ( ta , asctimebuf ) ;
2007-06-07 16:44:41 +08:00
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 ) ) ;
}
2010-03-12 18:28:59 +08:00
# if defined(PHP_WIN32)
2018-09-08 19:57:01 +08:00
if ( IsDebuggerPresent ( ) ) {
OutputDebugString ( memory_leak_buf ) ;
} else {
fprintf ( stderr , " %s " , memory_leak_buf ) ;
}
2010-03-12 18:28:59 +08:00
# else
2006-11-23 16:37:21 +08:00
fprintf ( stderr , " %s " , memory_leak_buf ) ;
2010-03-12 18:28:59 +08:00
# endif
1999-06-01 03:58:20 +08:00
}
1999-06-01 01:40:15 +08:00
break ;
1999-04-08 05:05:13 +08:00
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-26 03:35:44 +08:00
2010-03-12 18:28:59 +08:00
2014-12-14 06:06:14 +08:00
void php_on_timeout ( int seconds )
2002-09-19 23:54:23 +08:00
{
PG ( connection_status ) | = PHP_CONNECTION_TIMEOUT ;
}
2000-05-19 03:45:34 +08:00
# if PHP_SIGCHILD
2001-06-06 21:06:12 +08:00
/* {{{ sigchld_handler
*/
2000-05-19 18:48:05 +08:00
static void sigchld_handler ( int apar )
2000-05-19 03:45:34 +08:00
{
2011-06-03 05:16:50 +08:00
int errno_save = errno ;
2002-05-10 03:58:39 +08:00
while ( waitpid ( - 1 , NULL , WNOHANG ) > 0 ) ;
signal ( SIGCHLD , sigchld_handler ) ;
2011-06-03 05:16:50 +08:00
errno = errno_save ;
2000-05-19 03:45:34 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-05-19 03:45:34 +08:00
# endif
2001-06-06 21:06:12 +08:00
/* {{{ php_request_startup
*/
2014-12-14 06:06:14 +08:00
int php_request_startup ( void )
1999-04-08 05:05:13 +08:00
{
2001-07-21 22:27:56 +08:00
int retval = SUCCESS ;
2017-03-04 17:39:13 +08:00
zend_interned_strings_activate ( ) ;
2010-04-24 21:32:30 +08:00
# ifdef HAVE_DTRACE
2013-08-14 11:42:39 +08:00
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 ) ) ;
2010-04-24 21:32:30 +08:00
# endif /* HAVE_DTRACE */
2003-01-29 08:49:09 +08:00
# ifdef PHP_WIN32
2016-02-19 02:13:07 +08:00
# if defined(ZTS)
_configthreadlocale ( _ENABLE_PER_THREAD_LOCALE ) ;
# endif
2006-11-17 19:40:52 +08:00
PG ( com_initialized ) = 0 ;
2003-01-29 08:49:09 +08:00
# endif
2000-05-19 03:45:34 +08:00
# if PHP_SIGCHILD
2001-08-05 09:43:02 +08:00
signal ( SIGCHLD , sigchld_handler ) ;
2000-05-19 03:45:34 +08:00
# endif
2001-07-21 22:27:56 +08:00
zend_try {
2009-10-05 21:56:49 +08:00
PG ( in_error_log ) = 0 ;
2001-07-21 22:27:56 +08:00
PG ( during_request_startup ) = 1 ;
2007-07-15 23:21:12 +08:00
2014-12-14 06:06:14 +08:00
php_output_activate ( ) ;
1999-04-21 12:02:11 +08:00
2001-07-21 22:27:56 +08:00
/* initialize global variables */
PG ( modules_activated ) = 0 ;
PG ( header_is_being_sent ) = 0 ;
PG ( connection_status ) = PHP_CONNECTION_NORMAL ;
2007-07-10 01:27:24 +08:00
PG ( in_user_include ) = 0 ;
2007-07-15 23:21:12 +08:00
2014-12-14 06:06:14 +08:00
zend_activate ( ) ;
sapi_activate ( ) ;
2000-04-11 01:39:11 +08:00
2017-10-15 01:50:30 +08:00
# ifdef ZEND_SIGNALS
2014-12-14 06:06:14 +08:00
zend_signal_activate ( ) ;
2017-10-15 01:50:30 +08:00
# endif
2011-06-03 05:16:50 +08:00
2002-11-12 22:40:00 +08:00
if ( PG ( max_input_time ) = = - 1 ) {
2008-03-19 05:42:50 +08:00
zend_set_timeout ( EG ( timeout_seconds ) , 1 ) ;
2002-11-12 22:40:00 +08:00
} else {
2008-03-19 05:42:50 +08:00
zend_set_timeout ( PG ( max_input_time ) , 1 ) ;
2002-11-12 22:40:00 +08:00
}
2000-06-16 10:27:47 +08:00
2010-04-27 07:53:30 +08:00
/* Disable realpath cache if an open_basedir is set */
if ( PG ( open_basedir ) & & * PG ( open_basedir ) ) {
2006-05-16 08:39:32 +08:00
CWDG ( realpath_cache_size_limit ) = 0 ;
}
2001-07-21 22:27:56 +08:00
if ( PG ( expose_php ) ) {
sapi_add_header ( SAPI_PHP_VERSION_HEADER , sizeof ( SAPI_PHP_VERSION_HEADER ) - 1 , 1 ) ;
}
1999-12-03 13:03:16 +08:00
2001-07-21 22:27:56 +08:00
if ( PG ( output_handler ) & & PG ( output_handler ) [ 0 ] ) {
2014-02-10 14:04:30 +08:00
zval oh ;
2010-05-31 18:29:43 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & oh , PG ( output_handler ) ) ;
2014-12-14 06:06:14 +08:00
php_output_start_user ( & oh , 0 , PHP_OUTPUT_HANDLER_STDFLAGS ) ;
2010-05-31 18:29:43 +08:00
zval_ptr_dtor ( & oh ) ;
2002-10-03 19:18:39 +08:00
} else if ( PG ( output_buffering ) ) {
2014-12-14 06:06:14 +08:00
php_output_start_user ( NULL , PG ( output_buffering ) > 1 ? PG ( output_buffering ) : 0 , PHP_OUTPUT_HANDLER_STDFLAGS ) ;
2002-10-03 19:18:39 +08:00
} else if ( PG ( implicit_flush ) ) {
2014-12-14 06:06:14 +08:00
php_output_set_implicit_flush ( 1 ) ;
2001-07-21 22:27:56 +08:00
}
2000-09-09 23:02:15 +08:00
2001-07-21 22:27:56 +08:00
/* We turn this off in php_execute_script() */
/* PG(during_request_startup) = 0; */
2000-09-09 23:02:15 +08:00
2014-12-14 06:06:14 +08:00
php_hash_environment ( ) ;
zend_activate_modules ( ) ;
2001-07-21 22:27:56 +08:00
PG ( modules_activated ) = 1 ;
} zend_catch {
retval = FAILURE ;
} zend_end_try ( ) ;
2000-10-27 02:32:38 +08:00
2007-09-24 19:53:40 +08:00
SG ( sapi_started ) = 1 ;
2001-07-21 22:27:56 +08:00
return retval ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_request_shutdown
*/
1999-04-26 22:00:49 +08:00
void php_request_shutdown ( void * dummy )
1999-04-08 05:05:13 +08:00
{
2004-02-11 01:55:32 +08:00
zend_bool report_memleaks ;
1999-04-08 05:05:13 +08:00
2017-02-10 01:40:33 +08:00
EG ( flags ) | = EG_FLAGS_IN_SHUTDOWN ;
1999-04-08 05:05:13 +08:00
2004-02-11 01:55:32 +08:00
report_memleaks = PG ( report_memleaks ) ;
2007-07-15 23:21:12 +08:00
2014-07-03 03:29:53 +08:00
/* EG(current_execute_data) points into nirvana and therefore cannot be safely accessed
2003-07-31 00:15:03 +08:00
* inside zend_executor callback functions .
*/
2014-07-03 02:03:21 +08:00
EG ( current_execute_data ) = NULL ;
2003-02-20 00:17:15 +08:00
2014-12-14 06:06:14 +08:00
php_deactivate_ticks ( ) ;
2008-06-25 20:18:36 +08:00
2005-09-15 04:08:31 +08:00
/* 1. Call all possible shutdown functions registered with register_shutdown_function() */
2005-04-28 15:50:53 +08:00
if ( PG ( modules_activated ) ) zend_try {
2014-12-14 06:06:14 +08:00
php_call_shutdown_functions ( ) ;
2005-04-28 15:50:53 +08:00
} zend_end_try ( ) ;
2007-07-15 23:21:12 +08:00
2005-09-15 04:08:31 +08:00
/* 2. Call all possible __destruct() functions */
zend_try {
2014-12-14 06:06:14 +08:00
zend_call_destructors ( ) ;
2005-09-15 04:08:31 +08:00
} zend_end_try ( ) ;
2005-04-28 15:50:53 +08:00
/* 3. Flush all output buffers */
2001-07-21 22:27:56 +08:00
zend_try {
2008-09-17 08:20:30 +08:00
zend_bool send_buffer = SG ( request_info ) . headers_only ? 0 : 1 ;
2010-05-31 18:29:43 +08:00
2008-09-17 08:20:30 +08:00
if ( CG ( unclean_shutdown ) & & PG ( last_error_type ) = = E_ERROR & &
2014-12-14 06:06:14 +08:00
( size_t ) PG ( memory_limit ) < zend_memory_usage ( 1 )
2010-05-31 18:29:43 +08:00
) {
2008-09-17 08:20:30 +08:00
send_buffer = 0 ;
}
2010-05-31 18:29:43 +08:00
if ( ! send_buffer ) {
2014-12-14 06:06:14 +08:00
php_output_discard_all ( ) ;
2010-05-31 18:29:43 +08:00
} else {
2014-12-14 06:06:14 +08:00
php_output_end_all ( ) ;
2010-05-31 18:29:43 +08:00
}
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
1999-04-08 05:05:13 +08:00
2012-04-15 01:16:34 +08:00
/* 4. Reset max_execution_time (no longer executing php code after response sent) */
2011-06-03 05:16:50 +08:00
zend_try {
2014-12-14 06:06:14 +08:00
zend_unset_timeout ( ) ;
2011-06-03 05:16:50 +08:00
} zend_end_try ( ) ;
2012-04-15 01:16:34 +08:00
/* 5. Call all extensions RSHUTDOWN functions */
2000-05-30 02:45:06 +08:00
if ( PG ( modules_activated ) ) {
2014-12-14 06:06:14 +08:00
zend_deactivate_modules ( ) ;
2000-05-30 02:45:06 +08:00
}
2001-08-09 04:05:37 +08:00
2012-04-15 01:16:34 +08:00
/* 6. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */
zend_try {
2014-12-14 06:06:14 +08:00
php_output_deactivate ( ) ;
2012-04-15 01:16:34 +08:00
} zend_end_try ( ) ;
2016-03-25 12:34:22 +08:00
/* 7. Free shutdown functions */
if ( PG ( modules_activated ) ) {
php_free_shutdown_functions ( ) ;
}
/* 8. Destroy super-globals */
2001-08-09 04:05:37 +08:00
zend_try {
int i ;
for ( i = 0 ; i < NUM_TRACK_VARS ; i + + ) {
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( & PG ( http_globals ) [ i ] ) ;
2001-08-09 04:05:37 +08:00
}
} zend_end_try ( ) ;
2016-03-25 12:34:22 +08:00
/* 9. free request-bound globals */
2015-04-29 20:35:35 +08:00
php_free_request_globals ( ) ;
2007-07-15 22:15:02 +08:00
2016-03-25 12:34:22 +08:00
/* 10. Shutdown scanner/executor/compiler and restore ini entries */
2014-12-14 06:06:14 +08:00
zend_deactivate ( ) ;
1999-05-06 05:29:26 +08:00
2016-03-25 12:34:22 +08:00
/* 11. Call all extensions post-RSHUTDOWN functions */
2004-03-17 06:27:57 +08:00
zend_try {
2014-12-14 06:06:14 +08:00
zend_post_deactivate_modules ( ) ;
2004-03-17 06:27:57 +08:00
} zend_end_try ( ) ;
2016-03-25 12:34:22 +08:00
/* 12. SAPI related shutdown (free stuff) */
2001-07-21 22:27:56 +08:00
zend_try {
2014-12-14 06:06:14 +08:00
sapi_deactivate ( ) ;
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
1999-04-08 05:05:13 +08:00
2016-03-25 12:34:22 +08:00
/* 13. free virtual CWD memory */
2014-12-14 06:06:14 +08:00
virtual_cwd_deactivate ( ) ;
2013-10-17 16:40:43 +08:00
2016-03-25 12:34:22 +08:00
/* 14. Destroy stream hashes */
2005-05-16 16:37:14 +08:00
zend_try {
2014-12-14 06:06:14 +08:00
php_shutdown_stream_hashes ( ) ;
2005-05-16 16:37:14 +08:00
} zend_end_try ( ) ;
2016-03-25 12:34:22 +08:00
/* 15. Free Willy (here be crashes) */
2017-03-04 17:39:13 +08:00
zend_interned_strings_deactivate ( ) ;
2004-02-11 01:55:32 +08:00
zend_try {
2014-12-14 06:06:14 +08:00
shutdown_memory_manager ( CG ( unclean_shutdown ) | | ! report_memleaks , 0 ) ;
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
2000-09-01 00:02:51 +08:00
2003-01-29 08:49:09 +08:00
# ifdef PHP_WIN32
2006-11-17 19:40:52 +08:00
if ( PG ( com_initialized ) ) {
CoUninitialize ( ) ;
PG ( com_initialized ) = 0 ;
}
2003-01-29 08:49:09 +08:00
# endif
2010-04-24 21:32:30 +08:00
# ifdef HAVE_DTRACE
2013-08-14 11:42:39 +08:00
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 ) ) ;
2010-04-24 21:32:30 +08:00
# endif /* HAVE_DTRACE */
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2006-11-17 19:40:52 +08:00
/* {{{ php_com_initialize
*/
2014-12-14 06:06:14 +08:00
PHPAPI void php_com_initialize ( void )
2006-11-17 19:40:52 +08:00
{
# ifdef PHP_WIN32
if ( ! PG ( com_initialized ) ) {
2011-01-20 14:23:35 +08:00
if ( CoInitialize ( NULL ) = = S_OK ) {
PG ( com_initialized ) = 1 ;
}
2006-11-17 19:40:52 +08:00
}
# endif
}
/* }}} */
1999-08-26 00:24:14 +08:00
# ifdef ZTS
2001-06-06 21:06:12 +08:00
/* {{{ core_globals_ctor
*/
2014-12-14 06:06:14 +08:00
static void core_globals_ctor ( php_core_globals * core_globals )
1999-08-26 00:24:14 +08:00
{
2001-08-05 09:43:02 +08:00
memset ( core_globals , 0 , sizeof ( * core_globals ) ) ;
2017-06-05 04:15:29 +08:00
php_startup_ticks ( ) ;
1999-08-26 00:24:14 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-08-26 00:24:14 +08:00
# endif
2006-07-17 15:20:12 +08:00
/* {{{ core_globals_dtor
*/
2014-12-14 06:06:14 +08:00
static void core_globals_dtor ( php_core_globals * core_globals )
2006-07-17 15:20:12 +08:00
{
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 ) ;
}
2011-12-07 18:33:13 +08:00
if ( core_globals - > php_binary ) {
free ( core_globals - > php_binary ) ;
}
2009-03-27 10:34:06 +08:00
2014-12-14 06:06:14 +08:00
php_shutdown_ticks ( ) ;
2006-07-17 15:20:12 +08:00
}
/* }}} */
2008-12-31 21:25:21 +08:00
PHP_MINFO_FUNCTION ( php_core ) { /* {{{ */
php_info_print_table_start ( ) ;
php_info_print_table_row ( 2 , " PHP Version " , PHP_VERSION ) ;
2013-01-02 12:14:44 +08:00
php_info_print_table_end ( ) ;
2008-12-31 21:25:21 +08:00
DISPLAY_INI_ENTRIES ( ) ;
}
/* }}} */
2005-06-17 17:39:23 +08:00
/* {{{ php_register_extensions
2001-06-06 21:06:12 +08:00
*/
2017-12-14 23:43:44 +08:00
int php_register_extensions ( zend_module_entry * const * ptr , int count )
1999-12-08 04:49:01 +08:00
{
2017-12-14 23:43:44 +08:00
zend_module_entry * const * end = ptr + count ;
1999-12-08 04:49:01 +08:00
while ( ptr < end ) {
if ( * ptr ) {
2014-12-14 06:06:14 +08:00
if ( zend_register_internal_module ( * ptr ) = = NULL ) {
1999-12-08 04:49:01 +08:00
return FAILURE ;
}
}
ptr + + ;
}
return SUCCESS ;
}
2013-12-04 08:36:07 +08:00
/* 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
*/
2014-12-14 06:06:14 +08:00
static int php_register_extensions_bc ( zend_module_entry * ptr , int count )
2013-12-04 08:36:07 +08:00
{
while ( count - - ) {
2014-12-14 06:06:14 +08:00
if ( zend_register_internal_module ( ptr + + ) = = NULL ) {
2013-12-04 08:36:07 +08:00
return FAILURE ;
}
}
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-12-08 04:49:01 +08:00
2015-03-29 12:45:40 +08:00
# ifdef PHP_WIN32
2007-06-15 15:27:08 +08:00
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 ) {
2014-12-14 06:06:14 +08:00
if ( PG ( windows_show_crt_warning ) ) {
2011-09-13 18:38:12 +08:00
called = 1 ;
if ( function ) {
if ( file ) {
2014-09-19 16:04:12 +08:00
len = _snprintf ( buf , sizeof ( buf ) - 1 , " Invalid parameter detected in CRT function '%ws' (%ws:%u) " , function , file , line ) ;
2011-09-13 18:38:12 +08:00
} else {
len = _snprintf ( buf , sizeof ( buf ) - 1 , " Invalid parameter detected in CRT function '%ws' " , function ) ;
}
2007-06-15 15:27:08 +08:00
} else {
2011-09-13 18:38:12 +08:00
len = _snprintf ( buf , sizeof ( buf ) - 1 , " Invalid CRT parameter detected (function not known) " ) ;
2007-06-15 15:27:08 +08:00
}
2011-09-13 18:38:12 +08:00
zend_error ( E_WARNING , " %s " , buf ) ;
called = 0 ;
2007-06-15 15:27:08 +08:00
}
}
}
# endif
1999-12-08 04:49:01 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_module_startup
*/
2016-11-26 22:18:42 +08:00
int php_module_startup ( sapi_module_struct * sf , zend_module_entry * additional_modules , uint32_t num_additional_modules )
1999-04-08 05:05:13 +08:00
{
zend_utility_functions zuf ;
zend_utility_values zuv ;
2010-11-03 02:06:39 +08:00
int retval = SUCCESS , module_number = 0 ; /* for REGISTER_INI_ENTRIES() */
2017-02-22 19:31:06 +08:00
char * php_os ;
2008-12-31 21:25:21 +08:00
zend_module_entry * module ;
2011-01-20 14:23:35 +08:00
2017-02-12 01:55:32 +08:00
# ifdef PHP_WIN32
WORD wVersionRequested = MAKEWORD ( 2 , 0 ) ;
WSADATA wsaData ;
2017-02-22 19:31:06 +08:00
2010-04-13 19:14:04 +08:00
php_os = " WINNT " ;
2015-03-29 12:45:40 +08:00
2007-06-15 15:27:08 +08:00
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 ) ;
}
2008-05-21 23:55:31 +08:00
/* Disable the message box for assertions.*/
_CrtSetReportMode ( _CRT_ASSERT , 0 ) ;
1999-12-18 04:55:31 +08:00
# else
2015-02-21 11:35:16 +08:00
php_os = PHP_OS ;
1999-12-18 04:55:31 +08:00
# endif
2011-06-16 09:41:34 +08:00
2001-07-28 19:36:37 +08:00
# ifdef ZTS
2015-02-21 11:35:16 +08:00
( void ) ts_resource ( 0 ) ;
2001-07-28 19:36:37 +08:00
# endif
2011-06-16 09:31:10 +08:00
# ifdef PHP_WIN32
2017-02-13 00:15:50 +08:00
if ( ! php_win32_init_random_bytes ( ) ) {
fprintf ( stderr , " \n crypt algorithm provider initialization failed \n " ) ;
return FAILURE ;
}
2011-06-16 09:31:10 +08:00
# endif
2004-03-24 21:31:34 +08:00
module_shutdown = 0 ;
2004-03-24 21:33:26 +08:00
module_startup = 1 ;
2014-12-14 06:06:14 +08:00
sapi_initialize_empty_request ( ) ;
sapi_activate ( ) ;
1999-04-24 06:45:01 +08:00
if ( module_initialized ) {
1999-04-08 05:05:13 +08:00
return SUCCESS ;
}
1999-05-03 02:07:41 +08:00
sapi_module = * sf ;
1999-04-27 04:20:12 +08:00
1999-09-12 11:25:02 +08:00
php_output_startup ( ) ;
1999-04-08 05:05:13 +08:00
2015-02-21 11:35:16 +08:00
# ifdef ZTS
2019-03-14 08:01:01 +08:00
ts_allocate_fast_id ( & core_globals_id , & core_globals_offset , sizeof ( php_core_globals ) , ( ts_allocate_ctor ) core_globals_ctor , ( ts_allocate_dtor ) core_globals_dtor ) ;
2015-02-21 11:35:16 +08:00
# 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
2017-07-19 20:35:10 +08:00
memset ( & core_globals , 0 , sizeof ( core_globals ) ) ;
2015-02-21 11:35:16 +08:00
php_startup_ticks ( ) ;
# endif
gc_globals_ctor ( ) ;
2015-02-13 18:25:44 +08:00
zuf . error_function = php_error_cb ;
zuf . printf_function = php_printf ;
2018-12-26 22:34:03 +08:00
zuf . write_function = php_output_write ;
2015-02-13 18:25:44 +08:00
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 ;
2016-12-19 00:53:27 +08:00
zuf . printf_to_smart_string_function = php_printf_to_smart_string ;
zuf . printf_to_smart_str_function = php_printf_to_smart_str ;
2015-02-13 18:25:44 +08:00
zuf . getenv_function = sapi_getenv ;
zuf . resolve_path_function = php_resolve_path_for_zend ;
2019-03-11 17:10:14 +08:00
zend_startup ( & zuf ) ;
2000-06-05 23:34:11 +08:00
setlocale ( LC_CTYPE , " " ) ;
2006-12-05 02:37:15 +08:00
zend_update_current_locale ( ) ;
1999-04-08 05:05:13 +08:00
2004-02-09 12:04:24 +08:00
# if HAVE_TZSET
tzset ( ) ;
# endif
2017-02-12 01:55:32 +08:00
# ifdef PHP_WIN32
2019-03-31 23:28:50 +08:00
# if PHP_LINKER_MAJOR == 14
/* Extend for other CRT if needed. */
char * img_err ;
if ( ! php_win32_crt_compatible ( " vcruntime140.dll " , & img_err ) ) {
php_error ( E_CORE_WARNING , img_err ) ;
efree ( img_err ) ;
return FAILURE ;
}
# endif
2017-02-12 01:55:32 +08:00
/* start up winsock services */
if ( WSAStartup ( wVersionRequested , & wsaData ) ! = 0 ) {
php_printf ( " \n winsock.dll unusable. %d \n " , WSAGetLastError ( ) ) ;
return FAILURE ;
}
2019-02-09 10:10:31 +08:00
php_win32_signal_ctrl_handler_init ( ) ;
2017-02-12 01:55:32 +08:00
# endif
2000-10-21 02:25:16 +08:00
le_index_ptr = zend_register_list_destructors_ex ( NULL , NULL , " index pointer " , 0 ) ;
1999-04-08 05:05:13 +08:00
2008-02-05 04:39:21 +08:00
/* Register constants */
2010-03-12 18:28:59 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_VERSION " , PHP_VERSION , sizeof ( PHP_VERSION ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2014-08-26 01:24:55 +08:00
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 ) ;
2010-03-11 18:24:29 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_EXTRA_VERSION " , PHP_EXTRA_VERSION , sizeof ( PHP_EXTRA_VERSION ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2014-08-26 01:24:55 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_VERSION_ID " , PHP_VERSION_ID , CONST_PERSISTENT | CONST_CS ) ;
2010-03-12 18:28:59 +08:00
# ifdef ZTS
2014-08-26 01:24:55 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_ZTS " , 1 , CONST_PERSISTENT | CONST_CS ) ;
2010-03-12 18:28:59 +08:00
# else
2014-08-26 01:24:55 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_ZTS " , 0 , CONST_PERSISTENT | CONST_CS ) ;
2010-03-12 18:28:59 +08:00
# endif
2014-08-26 01:24:55 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_DEBUG " , PHP_DEBUG , CONST_PERSISTENT | CONST_CS ) ;
2008-02-05 04:39:21 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_OS " , php_os , strlen ( php_os ) , CONST_PERSISTENT | CONST_CS ) ;
2017-02-22 19:31:06 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_OS_FAMILY " , PHP_OS_FAMILY , sizeof ( PHP_OS_FAMILY ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2018-04-28 06:20:49 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_SAPI " , sapi_module . name , strlen ( sapi_module . name ) , CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE ) ;
2008-02-05 04:39:21 +08:00
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 ) ;
2011-04-20 05:43:22 +08:00
# ifndef PHP_WIN32
2011-04-18 17:50:32 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_MANDIR " , PHP_MANDIR , sizeof ( PHP_MANDIR ) - 1 , CONST_PERSISTENT | CONST_CS ) ;
2011-04-20 05:43:22 +08:00
# endif
2008-02-05 04:39:21 +08:00
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 ) ;
2014-08-26 01:24:55 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_MAXPATHLEN " , MAXPATHLEN , CONST_PERSISTENT | CONST_CS ) ;
2014-08-26 02:22:49 +08:00
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 ) ;
2014-08-26 03:20:44 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_INT_SIZE " , SIZEOF_ZEND_LONG , CONST_PERSISTENT | CONST_CS ) ;
2016-07-03 20:16:43 +08:00
REGISTER_MAIN_LONG_CONSTANT ( " PHP_FD_SETSIZE " , FD_SETSIZE , CONST_PERSISTENT | CONST_CS ) ;
2016-10-27 00:10:44 +08:00
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 ) ;
2008-02-05 04:39:21 +08:00
2009-06-04 14:59:46 +08:00
# ifdef PHP_WIN32
2014-08-26 01:24:55 +08:00
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 ) ;
2009-06-04 14:59:46 +08:00
# endif
2014-12-14 06:06:14 +08:00
php_binary_init ( ) ;
2011-12-07 18:33:13 +08:00
if ( PG ( php_binary ) ) {
2018-04-28 06:20:49 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_BINARY " , PG ( php_binary ) , strlen ( PG ( php_binary ) ) , CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE ) ;
2011-12-07 18:33:13 +08:00
} else {
2018-04-28 06:20:49 +08:00
REGISTER_MAIN_STRINGL_CONSTANT ( " PHP_BINARY " , " " , 0 , CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE ) ;
2011-12-07 18:33:13 +08:00
}
2014-12-14 06:06:14 +08:00
php_output_register_constants ( ) ;
php_rfc1867_register_constants ( ) ;
2008-02-05 04:39:21 +08:00
2001-02-21 09:43:15 +08:00
/* this will read in php.ini, set up the configuration parameters,
2007-07-15 23:34:28 +08:00
load zend extensions and register php function extensions
2001-02-21 09:43:15 +08:00
to be loaded later */
2014-12-14 06:06:14 +08:00
if ( php_init_config ( ) = = FAILURE ) {
1999-04-08 05:05:13 +08:00
return FAILURE ;
}
2005-09-02 22:05:46 +08:00
/* Register PHP core ini entries */
REGISTER_INI_ENTRIES ( ) ;
/* Register Zend ini entries */
2014-12-14 06:06:14 +08:00
zend_register_standard_ini_entries ( ) ;
2005-09-02 22:05:46 +08:00
2017-08-14 06:44:19 +08:00
# ifdef ZEND_WIN32
/* Until the current ini values was setup, the current cp is 65001.
2018-08-10 10:19:55 +08:00
If the actual ini values are different , some stuff needs to be updated .
2017-08-14 06:44:19 +08:00
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
2010-04-27 07:53:30 +08:00
/* Disable realpath cache if an open_basedir is set */
if ( PG ( open_basedir ) & & * PG ( open_basedir ) ) {
2004-10-05 08:42:25 +08:00
CWDG ( realpath_cache_size_limit ) = 0 ;
}
2017-08-23 06:34:06 +08:00
PG ( have_called_openlog ) = 0 ;
2002-03-16 05:03:08 +08:00
/* initialize stream wrappers registry
* ( this uses configuration parameters from php . ini )
2001-02-21 09:43:15 +08:00
*/
2014-12-14 06:06:14 +08:00
if ( php_init_stream_wrappers ( module_number ) = = FAILURE ) {
2002-03-16 05:03:08 +08:00
php_printf ( " PHP: Unable to initialize stream url wrappers. \n " ) ;
2000-10-13 08:09:31 +08:00
return FAILURE ;
}
2007-07-15 23:21:12 +08:00
2003-04-16 20:44:08 +08:00
zuv . html_errors = 1 ;
2014-12-14 06:06:14 +08:00
php_startup_auto_globals ( ) ;
1999-04-10 19:22:18 +08:00
zend_set_utility_values ( & zuv ) ;
2014-12-14 06:06:14 +08:00
php_startup_sapi_content_types ( ) ;
1999-04-10 19:22:18 +08:00
2013-03-03 23:44:46 +08:00
/* startup extensions statically compiled in */
2014-12-14 06:06:14 +08:00
if ( php_register_internal_extensions_func ( ) = = FAILURE ) {
1999-12-08 04:49:01 +08:00
php_printf ( " Unable to start builtin modules \n " ) ;
1999-04-08 05:05:13 +08:00
return FAILURE ;
}
2004-02-25 18:58:06 +08:00
2002-09-19 05:57:42 +08:00
/* start additional PHP extensions */
2014-12-14 06:06:14 +08:00
php_register_extensions_bc ( additional_modules , num_additional_modules ) ;
2002-09-19 05:57:42 +08:00
2001-02-21 09:43:15 +08:00
/* load and startup extensions compiled as shared objects (aka DLLs)
as requested by php . ini entries
2014-11-20 03:59:31 +08:00
these are loaded after initialization of internal extensions
2001-02-21 09:43:15 +08:00
as extensions * might * rely on things from ext / standard
which is always an internal extension and to be initialized
2002-05-10 03:58:39 +08:00
ahead of all other internals
2001-02-21 09:43:15 +08:00
*/
2014-12-14 06:06:14 +08:00
php_ini_register_extensions ( ) ;
zend_startup_modules ( ) ;
2001-02-21 09:43:15 +08:00
2002-09-19 05:57:42 +08:00
/* start Zend extensions */
2000-09-28 03:46:47 +08:00
zend_startup_extensions ( ) ;
2001-02-21 09:43:15 +08:00
2014-12-14 06:06:14 +08:00
zend_collect_module_handlers ( ) ;
2010-10-15 15:30:24 +08:00
2008-12-31 22:27:09 +08:00
/* register additional functions */
if ( sapi_module . additional_functions ) {
2014-02-10 14:04:30 +08:00
if ( ( module = zend_hash_str_find_ptr ( & module_registry , " standard " , sizeof ( " standard " ) - 1 ) ) ! = NULL ) {
2008-12-31 22:27:09 +08:00
EG ( current_module ) = module ;
2014-12-14 06:06:14 +08:00
zend_register_functions ( NULL , sapi_module . additional_functions , NULL , MODULE_PERSISTENT ) ;
2008-12-31 22:27:09 +08:00
EG ( current_module ) = NULL ;
}
}
2013-01-02 12:14:44 +08:00
2009-07-29 08:17:10 +08:00
/* disable certain classes and functions as requested by php.ini */
2014-12-14 06:06:14 +08:00
php_disable_functions ( ) ;
php_disable_classes ( ) ;
2009-07-29 08:17:10 +08:00
2008-12-31 21:25:21 +08:00
/* make core report what it should */
2014-02-10 14:04:30 +08:00
if ( ( module = zend_hash_str_find_ptr ( & module_registry , " core " , sizeof ( " core " ) - 1 ) ) ! = NULL ) {
2008-12-31 21:25:21 +08:00
module - > version = PHP_VERSION ;
module - > info_func = PHP_MINFO ( php_core ) ;
}
2018-10-29 20:25:17 +08:00
module_initialized = 1 ;
2017-10-18 22:18:54 +08:00
if ( zend_post_startup ( ) ! = SUCCESS ) {
return FAILURE ;
}
2002-09-17 17:07:10 +08:00
2009-09-04 19:02:40 +08:00
/* Check for deprecated directives */
2019-03-04 13:06:10 +08:00
/* NOTE: If you add anything here, remember to add it to build/Makefile.global! */
2009-09-04 19:02:40 +08:00
{
2010-04-12 09:52:55 +08:00
struct {
const long error_level ;
const char * phrase ;
2019-01-28 19:54:46 +08:00
const char * directives [ 18 ] ; /* Remember to change this if the number of directives change */
2010-04-27 07:53:30 +08:00
} directives [ 2 ] = {
2010-04-12 09:52:55 +08:00
{
2013-01-02 12:14:44 +08:00
E_DEPRECATED ,
2017-02-03 04:15:36 +08:00
" Directive '%s' is deprecated " ,
2010-04-12 09:52:55 +08:00
{
NULL
}
2013-01-02 12:14:44 +08:00
} ,
2010-04-12 09:52:55 +08:00
{
2013-01-02 12:14:44 +08:00
E_CORE_ERROR ,
" Directive '%s' is no longer available in PHP " ,
2010-04-12 09:52:55 +08:00
{
2010-04-27 07:53:30 +08:00
" allow_call_time_pass_reference " ,
2014-09-10 05:14:19 +08:00
" asp_tags " ,
2013-01-02 12:14:44 +08:00
" 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 " ,
2019-01-28 19:54:46 +08:00
" track_errors " ,
2010-04-12 09:52:55 +08:00
NULL
}
}
2009-09-04 19:02:40 +08:00
} ;
2010-04-12 09:52:55 +08:00
unsigned int i ;
2013-01-02 12:14:44 +08:00
2010-11-03 02:06:39 +08:00
zend_try {
/* 2 = Count of deprecation structs */
for ( i = 0 ; i < 2 ; i + + ) {
const char * * p = directives [ i ] . directives ;
2009-09-04 19:02:40 +08:00
2010-11-03 02:06:39 +08:00
while ( * p ) {
2014-08-26 01:24:55 +08:00
zend_long value ;
2010-04-12 09:52:55 +08:00
2014-08-26 01:24:55 +08:00
if ( cfg_get_long ( ( char * ) * p , & value ) = = SUCCESS & & value ) {
2010-11-03 02:06:39 +08:00
zend_error ( directives [ i ] . error_level , directives [ i ] . phrase , * p ) ;
}
2010-04-12 09:52:55 +08:00
2010-11-03 02:06:39 +08:00
+ + p ;
2010-04-12 09:52:55 +08:00
}
}
2010-11-03 02:06:39 +08:00
} zend_catch {
retval = FAILURE ;
} zend_end_try ( ) ;
2009-09-04 19:02:40 +08:00
}
2013-01-02 12:14:44 +08:00
2017-06-27 22:26:54 +08:00
virtual_cwd_deactivate ( ) ;
2014-12-14 06:06:14 +08:00
sapi_deactivate ( ) ;
2009-09-21 17:52:19 +08:00
module_startup = 0 ;
2014-12-14 06:06:14 +08:00
shutdown_memory_manager ( 1 , 0 ) ;
virtual_cwd_activate ( ) ;
2009-09-04 19:02:40 +08:00
2017-11-03 04:29:21 +08:00
zend_interned_strings_switch_storage ( 1 ) ;
2017-03-04 17:39:13 +08:00
2017-11-03 04:52:50 +08:00
# if ZEND_RC_DEBUG
zend_rc_debug = 1 ;
# endif
2001-02-21 09:43:15 +08:00
/* we're done */
2010-11-03 02:06:39 +08:00
return retval ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_module_shutdown_wrapper
*/
1999-05-03 02:07:41 +08:00
int php_module_shutdown_wrapper ( sapi_module_struct * sapi_globals )
{
2014-12-14 06:06:14 +08:00
php_module_shutdown ( ) ;
1999-05-03 02:07:41 +08:00
return SUCCESS ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-05-03 02:07:41 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_module_shutdown
*/
2014-12-14 06:06:14 +08:00
void php_module_shutdown ( void )
1999-04-08 05:05:13 +08:00
{
1999-04-10 03:09:29 +08:00
int module_number = 0 ; /* for UNREGISTER_INI_ENTRIES() */
1999-04-08 05:05:13 +08:00
2003-09-02 20:12:05 +08:00
module_shutdown = 1 ;
1999-04-24 08:12:00 +08:00
if ( ! module_initialized ) {
return ;
}
2000-02-11 00:52:07 +08:00
2017-11-03 04:29:21 +08:00
zend_interned_strings_switch_storage ( 0 ) ;
2017-11-03 04:52:50 +08:00
# if ZEND_RC_DEBUG
zend_rc_debug = 0 ;
# endif
2011-06-16 09:31:10 +08:00
# ifdef PHP_WIN32
2017-02-13 00:15:50 +08:00
( void ) php_win32_shutdown_random_bytes ( ) ;
2019-02-09 10:10:31 +08:00
php_win32_signal_ctrl_handler_shutdown ( ) ;
2011-06-16 09:31:10 +08:00
# endif
2014-12-14 06:06:14 +08:00
sapi_flush ( ) ;
1999-04-08 05:05:13 +08:00
2014-12-14 06:06:14 +08:00
zend_shutdown ( ) ;
2013-01-02 12:14:44 +08:00
2017-02-12 01:55:32 +08:00
# ifdef PHP_WIN32
/*close winsock */
WSACleanup ( ) ;
# endif
2007-07-15 23:34:28 +08:00
/* Destroys filter & transport registries too */
2014-12-14 06:06:14 +08:00
php_shutdown_stream_wrappers ( module_number ) ;
2002-03-16 05:03:08 +08:00
1999-04-10 03:09:29 +08:00
UNREGISTER_INI_ENTRIES ( ) ;
2001-08-16 17:40:05 +08:00
/* close down the ini config */
php_shutdown_config ( ) ;
2001-12-17 06:45:57 +08:00
# ifndef ZTS
2014-12-14 06:06:14 +08:00
zend_ini_shutdown ( ) ;
shutdown_memory_manager ( CG ( unclean_shutdown ) , 1 ) ;
2004-05-24 00:02:36 +08:00
# else
2014-12-14 06:06:14 +08:00
zend_ini_global_shutdown ( ) ;
2001-08-05 09:43:02 +08:00
# endif
2001-08-16 17:40:05 +08:00
2010-05-31 18:29:43 +08:00
php_output_shutdown ( ) ;
2007-02-08 05:01:06 +08:00
2017-10-31 07:16:46 +08:00
# ifndef ZTS
zend_interned_strings_dtor ( ) ;
# endif
2018-10-26 01:30:51 +08:00
if ( zend_post_shutdown_cb ) {
void ( * cb ) ( void ) = zend_post_shutdown_cb ;
zend_post_shutdown_cb = NULL ;
cb ( ) ;
}
1999-04-24 06:45:01 +08:00
module_initialized = 0 ;
2007-06-15 15:27:08 +08:00
2010-05-31 18:29:43 +08:00
# ifndef ZTS
2014-12-14 06:06:14 +08:00
core_globals_dtor ( & core_globals ) ;
gc_globals_dtor ( ) ;
2010-05-31 18:29:43 +08:00
# else
ts_free_id ( core_globals_id ) ;
# endif
2015-03-29 12:45:40 +08:00
# ifdef PHP_WIN32
2007-06-15 15:27:08 +08:00
if ( old_invalid_parameter_handler = = NULL ) {
_set_invalid_parameter_handler ( old_invalid_parameter_handler ) ;
}
# endif
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_execute_script
*/
2014-12-14 06:06:14 +08:00
PHPAPI int php_execute_script ( zend_file_handle * primary_file )
2000-10-27 05:16:12 +08:00
{
zend_file_handle * prepend_file_p , * append_file_p ;
2015-01-27 23:28:31 +08:00
zend_file_handle prepend_file = { { 0 } , NULL , NULL , 0 , 0 } , append_file = { { 0 } , NULL , NULL , 0 , 0 } ;
2015-01-03 17:22:58 +08:00
# if HAVE_BROKEN_GETCWD
2013-04-05 10:24:12 +08:00
volatile int old_cwd_fd = - 1 ;
2003-03-17 21:40:45 +08:00
# else
2000-10-27 05:16:12 +08:00
char * old_cwd ;
2013-10-31 03:13:14 +08:00
ALLOCA_FLAG ( use_heap )
2003-03-17 21:40:45 +08:00
# endif
2002-02-15 04:16:08 +08:00
int retval = 0 ;
2000-10-27 05:16:12 +08:00
2000-11-22 12:23:26 +08:00
EG ( exit_status ) = 0 ;
2003-03-17 21:40:45 +08:00
# ifndef HAVE_BROKEN_GETCWD
# define OLD_CWD_SIZE 4096
2013-10-31 03:13:14 +08:00
old_cwd = do_alloca ( OLD_CWD_SIZE , use_heap ) ;
2000-08-28 03:56:22 +08:00
old_cwd [ 0 ] = ' \0 ' ;
2003-03-17 21:40:45 +08:00
# endif
2000-05-29 01:19:49 +08:00
2001-07-21 22:27:56 +08:00
zend_try {
2006-03-10 04:32:22 +08:00
char realfile [ MAXPATHLEN ] ;
2000-02-11 23:59:30 +08:00
# ifdef PHP_WIN32
2009-10-14 03:58:59 +08:00
if ( primary_file - > filename ) {
2014-12-14 06:06:14 +08:00
UpdateIniFromRegistry ( ( char * ) primary_file - > filename ) ;
2009-10-14 03:58:59 +08:00
}
1999-04-18 23:09:46 +08:00
# endif
1999-04-08 05:05:13 +08:00
2001-07-21 22:27:56 +08:00
PG ( during_request_startup ) = 0 ;
2000-09-09 23:02:15 +08:00
2008-07-21 16:43:36 +08:00
if ( primary_file - > filename & & ! ( SG ( options ) & SAPI_OPTION_NO_CHDIR ) ) {
2003-03-17 21:40:45 +08:00
# if HAVE_BROKEN_GETCWD
/* this looks nasty to me */
old_cwd_fd = open ( " . " , 0 ) ;
# else
2011-05-17 00:58:02 +08:00
php_ignore_value ( VCWD_GETCWD ( old_cwd , OLD_CWD_SIZE - 1 ) ) ;
2003-03-17 21:40:45 +08:00
# endif
2001-07-21 22:27:56 +08:00
VCWD_CHDIR_FILE ( primary_file - > filename ) ;
}
2000-08-20 22:29:00 +08:00
2006-03-11 02:19:29 +08:00
/* 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
*/
2006-03-13 17:35:45 +08:00
if ( primary_file - > filename & &
2016-03-21 06:07:14 +08:00
strcmp ( " Standard input code " , primary_file - > filename ) & &
2007-07-15 23:21:12 +08:00
primary_file - > opened_path = = NULL & &
primary_file - > type ! = ZEND_HANDLE_FILENAME
) {
2014-12-14 06:06:14 +08:00
if ( expand_filepath ( primary_file - > filename , realfile ) ) {
2015-03-04 07:05:28 +08:00
primary_file - > opened_path = zend_string_init ( realfile , strlen ( realfile ) , 0 ) ;
zend_hash_add_empty_element ( & EG ( included_files ) , primary_file - > opened_path ) ;
2002-06-30 21:38:16 +08:00
}
}
2001-07-21 22:27:56 +08:00
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 ;
2001-11-27 02:57:44 +08:00
prepend_file . type = ZEND_HANDLE_FILENAME ;
2001-07-21 22:27:56 +08:00
prepend_file_p = & prepend_file ;
} else {
prepend_file_p = NULL ;
}
2002-09-30 03:22:39 +08:00
2001-07-21 22:27:56 +08:00
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 ;
2001-11-27 02:57:44 +08:00
append_file . type = ZEND_HANDLE_FILENAME ;
2001-07-21 22:27:56 +08:00
append_file_p = & append_file ;
} else {
append_file_p = NULL ;
}
2006-05-12 06:10:31 +08:00
if ( PG ( max_input_time ) ! = - 1 ) {
2003-02-27 06:19:01 +08:00
# ifdef PHP_WIN32
2014-12-14 06:06:14 +08:00
zend_unset_timeout ( ) ;
2003-02-27 06:19:01 +08:00
# endif
2009-11-15 08:31:42 +08:00
zend_set_timeout ( INI_INT ( " max_execution_time " ) , 0 ) ;
2006-04-07 19:44:03 +08:00
}
2007-07-15 23:34:28 +08:00
2015-03-03 16:25:43 +08:00
/*
If cli primary file has shabang line and there is a prepend file ,
2019-07-15 22:21:46 +08:00
the ` skip_shebang ` will be used by prepend file but not primary file ,
2015-03-03 16:25:43 +08:00
save it and restore after prepend file been executed .
*/
2019-07-15 22:21:46 +08:00
if ( CG ( skip_shebang ) & & prepend_file_p ) {
CG ( skip_shebang ) = 0 ;
2015-03-03 16:29:41 +08:00
if ( zend_execute_scripts ( ZEND_REQUIRE , NULL , 1 , prepend_file_p ) = = SUCCESS ) {
2019-07-15 22:21:46 +08:00
CG ( skip_shebang ) = 1 ;
2015-03-03 16:29:41 +08:00
retval = ( zend_execute_scripts ( ZEND_REQUIRE , NULL , 2 , primary_file , append_file_p ) = = SUCCESS ) ;
2015-03-03 16:25:43 +08:00
}
} else {
2015-03-03 16:29:41 +08:00
retval = ( zend_execute_scripts ( ZEND_REQUIRE , NULL , 3 , prepend_file_p , primary_file , append_file_p ) = = SUCCESS ) ;
2015-03-03 11:25:30 +08:00
}
2001-07-21 22:27:56 +08:00
} zend_end_try ( ) ;
2000-08-20 22:29:00 +08:00
2015-03-09 20:57:15 +08:00
if ( EG ( exception ) ) {
2015-03-10 15:04:01 +08:00
zend_try {
zend_exception_error ( EG ( exception ) , E_ERROR ) ;
} zend_end_try ( ) ;
2015-03-09 20:57:15 +08:00
}
2003-03-17 21:40:45 +08:00
# if HAVE_BROKEN_GETCWD
2003-05-13 10:26:42 +08:00
if ( old_cwd_fd ! = - 1 ) {
fchdir ( old_cwd_fd ) ;
close ( old_cwd_fd ) ;
}
2003-03-17 21:40:45 +08:00
# else
2001-07-21 22:27:56 +08:00
if ( old_cwd [ 0 ] ! = ' \0 ' ) {
2011-05-17 00:58:02 +08:00
php_ignore_value ( VCWD_CHDIR ( old_cwd ) ) ;
2001-07-21 22:27:56 +08:00
}
2013-11-01 04:42:55 +08:00
free_alloca ( old_cwd , use_heap ) ;
2003-03-17 21:40:45 +08:00
# endif
2002-02-15 04:16:08 +08:00
return retval ;
1999-04-08 05:05:13 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
1999-04-08 05:05:13 +08:00
2002-11-18 08:59:23 +08:00
/* {{{ php_execute_simple_script
*/
2014-12-14 06:06:14 +08:00
PHPAPI int php_execute_simple_script ( zend_file_handle * primary_file , zval * ret )
2002-11-18 08:59:23 +08:00
{
2003-03-04 22:12:39 +08:00
char * old_cwd ;
2013-11-01 04:42:55 +08:00
ALLOCA_FLAG ( use_heap )
2002-11-18 08:59:23 +08:00
2003-03-04 22:12:39 +08:00
EG ( exit_status ) = 0 ;
2002-11-18 08:59:23 +08:00
# define OLD_CWD_SIZE 4096
2013-11-01 04:42:55 +08:00
old_cwd = do_alloca ( OLD_CWD_SIZE , use_heap ) ;
2003-03-04 22:12:39 +08:00
old_cwd [ 0 ] = ' \0 ' ;
2007-07-15 23:21:12 +08:00
2003-03-04 22:12:39 +08:00
zend_try {
2002-11-18 08:59:23 +08:00
# ifdef PHP_WIN32
2009-10-14 03:58:59 +08:00
if ( primary_file - > filename ) {
2014-12-14 06:06:14 +08:00
UpdateIniFromRegistry ( ( char * ) primary_file - > filename ) ;
2009-10-14 03:58:59 +08:00
}
2002-11-18 08:59:23 +08:00
# endif
2003-03-04 22:12:39 +08:00
PG ( during_request_startup ) = 0 ;
2008-07-21 16:43:36 +08:00
if ( primary_file - > filename & & ! ( SG ( options ) & SAPI_OPTION_NO_CHDIR ) ) {
2011-05-17 00:58:02 +08:00
php_ignore_value ( VCWD_GETCWD ( old_cwd , OLD_CWD_SIZE - 1 ) ) ;
2003-03-04 22:12:39 +08:00
VCWD_CHDIR_FILE ( primary_file - > filename ) ;
}
2014-12-14 06:06:14 +08:00
zend_execute_scripts ( ZEND_REQUIRE , ret , 1 , primary_file ) ;
2003-03-04 22:12:39 +08:00
} zend_end_try ( ) ;
2007-07-15 23:21:12 +08:00
2003-03-04 22:12:39 +08:00
if ( old_cwd [ 0 ] ! = ' \0 ' ) {
2011-05-17 00:58:02 +08:00
php_ignore_value ( VCWD_CHDIR ( old_cwd ) ) ;
2003-03-04 22:12:39 +08:00
}
2013-11-01 04:42:55 +08:00
free_alloca ( old_cwd , use_heap ) ;
2003-03-04 22:12:39 +08:00
return EG ( exit_status ) ;
2002-11-18 08:59:23 +08:00
}
/* }}} */
2001-06-06 21:06:12 +08:00
/* {{{ php_handle_aborted_connection
*/
2000-10-30 00:00:42 +08:00
PHPAPI void php_handle_aborted_connection ( void )
{
PG ( connection_status ) = PHP_CONNECTION_ABORTED ;
2014-12-14 06:06:14 +08:00
php_output_set_status ( PHP_OUTPUT_DISABLED ) ;
2000-10-30 00:00:42 +08:00
if ( ! PG ( ignore_user_abort ) ) {
zend_bailout ( ) ;
}
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-10-30 00:00:42 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_handle_auth_data
*/
2014-12-14 06:06:14 +08:00
PHPAPI int php_handle_auth_data ( const char * auth )
2000-10-27 18:16:54 +08:00
{
int ret = - 1 ;
2003-03-04 22:12:39 +08:00
if ( auth & & auth [ 0 ] ! = ' \0 ' & & strncmp ( auth , " Basic " , 6 ) = = 0 ) {
2000-10-27 18:16:54 +08:00
char * pass ;
2014-02-24 18:48:22 +08:00
zend_string * user ;
2000-10-27 18:16:54 +08:00
2015-01-27 23:28:31 +08:00
user = php_base64_decode ( ( const unsigned char * ) auth + 6 , strlen ( auth ) - 6 ) ;
2000-10-27 18:16:54 +08:00
if ( user ) {
2015-06-30 18:59:27 +08:00
pass = strchr ( ZSTR_VAL ( user ) , ' : ' ) ;
2000-10-27 18:16:54 +08:00
if ( pass ) {
* pass + + = ' \0 ' ;
2015-06-30 18:59:27 +08:00
SG ( request_info ) . auth_user = estrndup ( ZSTR_VAL ( user ) , ZSTR_LEN ( user ) ) ;
2000-10-27 18:16:54 +08:00
SG ( request_info ) . auth_password = estrdup ( pass ) ;
ret = 0 ;
2015-01-03 17:22:58 +08:00
}
2014-08-26 01:24:55 +08:00
zend_string_free ( user ) ;
2000-10-27 18:16:54 +08:00
}
}
2000-10-27 18:28:57 +08:00
2003-03-04 22:12:39 +08:00
if ( ret = = - 1 ) {
2000-10-27 18:28:57 +08:00
SG ( request_info ) . auth_user = SG ( request_info ) . auth_password = NULL ;
2005-07-13 00:53:30 +08:00
} else {
SG ( request_info ) . auth_digest = NULL ;
2003-03-04 22:12:39 +08:00
}
2007-07-15 23:21:12 +08:00
2005-07-13 00:53:30 +08:00
if ( ret = = - 1 & & auth & & auth [ 0 ] ! = ' \0 ' & & strncmp ( auth , " Digest " , 7 ) = = 0 ) {
2005-11-25 08:02:16 +08:00
SG ( request_info ) . auth_digest = estrdup ( auth + 7 ) ;
2005-04-04 23:06:36 +08:00
ret = 0 ;
}
2005-07-13 00:53:30 +08:00
if ( ret = = - 1 ) {
SG ( request_info ) . auth_digest = NULL ;
}
2000-10-27 18:16:54 +08:00
return ret ;
}
2001-06-06 21:06:12 +08:00
/* }}} */
2000-10-27 18:16:54 +08:00
2001-06-06 21:06:12 +08:00
/* {{{ php_lint_script
*/
2014-12-14 06:06:14 +08:00
PHPAPI int php_lint_script ( zend_file_handle * file )
2000-07-28 23:21:20 +08:00
{
2000-08-10 03:23:53 +08:00
zend_op_array * op_array ;
2006-12-04 23:58:48 +08:00
int retval = FAILURE ;
2000-07-28 23:21:20 +08:00
2001-07-21 22:27:56 +08:00
zend_try {
2014-12-14 06:06:14 +08:00
op_array = zend_compile_file ( file , ZEND_INCLUDE ) ;
zend_destroy_file_handle ( file ) ;
2000-07-28 23:21:20 +08:00
2001-07-21 22:27:56 +08:00
if ( op_array ) {
2014-12-14 06:06:14 +08:00
destroy_op_array ( op_array ) ;
2001-07-21 22:27:56 +08:00
efree ( op_array ) ;
2004-12-11 06:59:25 +08:00
retval = SUCCESS ;
2001-07-21 22:27:56 +08:00
}
} zend_end_try ( ) ;
2015-03-09 20:57:15 +08:00
if ( EG ( exception ) ) {
zend_exception_error ( EG ( exception ) , E_ERROR ) ;
}
2001-02-22 19:30:53 +08:00
2004-12-11 06:59:25 +08:00
return retval ;
2000-07-28 23:21:20 +08:00
}
2001-06-06 21:06:12 +08:00
/* }}} */
2019-03-14 08:01:01 +08:00
# ifdef ZTS
/* {{{ php_reserve_tsrm_memory
*/
PHPAPI void php_reserve_tsrm_memory ( void )
{
tsrm_reserve (
TSRM_ALIGNED_SIZE ( sizeof ( zend_compiler_globals ) ) +
TSRM_ALIGNED_SIZE ( sizeof ( zend_executor_globals ) ) +
TSRM_ALIGNED_SIZE ( sizeof ( zend_php_scanner_globals ) ) +
TSRM_ALIGNED_SIZE ( sizeof ( zend_ini_scanner_globals ) ) +
TSRM_ALIGNED_SIZE ( sizeof ( virtual_cwd_globals ) ) +
# ifdef ZEND_SIGNALS
TSRM_ALIGNED_SIZE ( sizeof ( zend_signal_globals_t ) ) +
# endif
TSRM_ALIGNED_SIZE ( zend_mm_globals_size ( ) ) +
TSRM_ALIGNED_SIZE ( zend_gc_globals_size ( ) ) +
TSRM_ALIGNED_SIZE ( sizeof ( php_core_globals ) ) +
TSRM_ALIGNED_SIZE ( sizeof ( sapi_globals_struct ) )
) ;
}
/* }}} */
/* {{{ php_tsrm_startup
*/
PHPAPI int php_tsrm_startup ( void )
{
int ret = tsrm_startup ( 1 , 1 , 0 , NULL ) ;
php_reserve_tsrm_memory ( ) ;
( void ) ts_resource ( 0 ) ;
return ret ;
}
/* }}} */
# endif