diff options
Diffstat (limited to 'main')
50 files changed, 488 insertions, 589 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index 2a064bce48..c841c6e789 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -180,7 +180,7 @@ SAPI_API void sapi_handle_post(void *arg) static void sapi_read_post_data(void) { sapi_post_entry *post_entry; - uint content_type_length = (uint)strlen(SG(request_info).content_type); + uint32_t content_type_length = (uint32_t)strlen(SG(request_info).content_type); char *content_type = estrndup(SG(request_info).content_type, content_type_length); char *p; char oldchar=0; @@ -302,21 +302,21 @@ SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) } -static inline char *get_default_content_type(uint prefix_len, uint *len) +static inline char *get_default_content_type(uint32_t prefix_len, uint32_t *len) { char *mimetype, *charset, *content_type; - uint mimetype_len, charset_len; + uint32_t mimetype_len, charset_len; if (SG(default_mimetype)) { mimetype = SG(default_mimetype); - mimetype_len = (uint)strlen(SG(default_mimetype)); + mimetype_len = (uint32_t)strlen(SG(default_mimetype)); } else { mimetype = SAPI_DEFAULT_MIMETYPE; mimetype_len = sizeof(SAPI_DEFAULT_MIMETYPE) - 1; } if (SG(default_charset)) { charset = SG(default_charset); - charset_len = (uint)strlen(SG(default_charset)); + charset_len = (uint32_t)strlen(SG(default_charset)); } else { charset = SAPI_DEFAULT_CHARSET; charset_len = sizeof(SAPI_DEFAULT_CHARSET) - 1; @@ -344,7 +344,7 @@ static inline char *get_default_content_type(uint prefix_len, uint *len) SAPI_API char *sapi_get_default_content_type(void) { - uint len; + uint32_t len; return get_default_content_type(0, &len); } @@ -352,7 +352,7 @@ SAPI_API char *sapi_get_default_content_type(void) SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header) { - uint len; + uint32_t len; default_header->header = get_default_content_type(sizeof("Content-type: ")-1, &len); default_header->header_len = len; @@ -646,7 +646,7 @@ static void sapi_header_add_op(sapi_header_op_enum op, sapi_header_struct *sapi_ char sav = *colon_offset; *colon_offset = 0; - sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, (int)strlen(sapi_header->header)); + sapi_remove_header(&SG(sapi_headers).headers, sapi_header->header, strlen(sapi_header->header)); *colon_offset = sav; } } @@ -733,7 +733,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) return SUCCESS; } else { /* new line/NUL character safety check */ - uint i; + uint32_t i; for (i = 0; i < header_line_len; i++) { /* RFC 7230 ch. 3.2.4 deprecates folding support */ if (header_line[i] == '\n' || header_line[i] == '\r') { @@ -795,7 +795,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg) PHP_STRLCPY(newheader, "Content-type: ", newlen, sizeof("Content-type: ")-1); strlcat(newheader, mimetype, newlen); sapi_header.header = newheader; - sapi_header.header_len = (uint)(newlen - 1); + sapi_header.header_len = (uint32_t)(newlen - 1); efree(header_line); } efree(mimetype); @@ -855,7 +855,7 @@ SAPI_API int sapi_send_headers(void) * in case of an error situation. */ if (SG(sapi_headers).send_default_content_type && sapi_module.send_headers) { - uint len = 0; + uint32_t len = 0; char *default_mimetype = get_default_content_type(0, &len); if (default_mimetype && len) { @@ -902,7 +902,7 @@ SAPI_API int sapi_send_headers(void) if (SG(sapi_headers).http_status_line) { http_status_line.header = SG(sapi_headers).http_status_line; - http_status_line.header_len = (uint)strlen(SG(sapi_headers).http_status_line); + http_status_line.header_len = (uint32_t)strlen(SG(sapi_headers).http_status_line); } else { http_status_line.header = buf; http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code); diff --git a/main/SAPI.h b/main/SAPI.h index f857d3ec94..1516702edf 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -27,7 +27,6 @@ #include "zend_llist.h" #include "zend_operators.h" #ifdef PHP_WIN32 -#include "win95nt.h" #include "win32/php_stdint.h" #endif #include <sys/stat.h> @@ -273,7 +272,7 @@ struct _sapi_module_struct { struct _sapi_post_entry { char *content_type; - uint content_type_len; + uint32_t content_type_len; void (*post_reader)(void); void (*post_handler)(char *content_type_dup, void *arg); }; @@ -328,4 +327,6 @@ END_EXTERN_C() * tab-width: 4 * c-basic-offset: 4 * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ diff --git a/main/build-defs.h.in b/main/build-defs.h.in index 7748d739c7..fb9bc7f881 100644 --- a/main/build-defs.h.in +++ b/main/build-defs.h.in @@ -12,7 +12,7 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@php.net> | + | Author: Stig Sæther Bakken <ssb@php.net> | +----------------------------------------------------------------------+ */ @@ -89,3 +89,4 @@ #define PHP_CONFIG_FILE_PATH "@EXPANDED_PHP_CONFIG_FILE_PATH@" #define PHP_CONFIG_FILE_SCAN_DIR "@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@" #define PHP_SHLIB_SUFFIX "@SHLIB_DL_SUFFIX_NAME@" +#define PHP_SHLIB_EXT_PREFIX "" diff --git a/main/explicit_bzero.c b/main/explicit_bzero.c new file mode 100644 index 0000000000..e99e082e6d --- /dev/null +++ b/main/explicit_bzero.c @@ -0,0 +1,51 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2017 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#include "php.h" + +#ifndef HAVE_EXPLICIT_BZERO + +/* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ +/* + * Public domain. + * Written by Matthew Dempsky. + */ + +#include <string.h> + +__attribute__((weak)) void +__explicit_bzero_hook(void *dst, size_t siz) +{ +} + +PHPAPI void php_explicit_bzero(void *dst, size_t siz) +{ + memset(dst, 0, siz); + __explicit_bzero_hook(dst, siz); +} +#endif +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index e1f89ce5cc..12de33be83 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -55,8 +55,6 @@ #ifdef PHP_WIN32 #include <winsock2.h> -#elif defined(NETWARE) && defined(USE_WINSOCK) -#include <novsock2.h> #else #include <netinet/in.h> #include <netdb.h> @@ -65,7 +63,7 @@ #endif #endif -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) +#if defined(PHP_WIN32) || defined(__riscos__) #undef AF_UNIX #endif @@ -142,8 +140,8 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path char local_open_basedir[MAXPATHLEN]; char path_tmp[MAXPATHLEN]; char *path_file; - int resolved_basedir_len; - int resolved_name_len; + size_t resolved_basedir_len; + size_t resolved_name_len; size_t path_len; int nesting_level = 0; @@ -184,7 +182,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path } #endif -#if defined(PHP_WIN32) || defined(NETWARE) +#ifdef PHP_WIN32 path_file = strrchr(path_tmp, DEFAULT_SLASH); if (!path_file) { path_file = strrchr(path_tmp, '/'); @@ -197,7 +195,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path return -1; } else { path_len = path_file - path_tmp + 1; -#if defined(PHP_WIN32) || defined(NETWARE) +#ifdef PHP_WIN32 if (path_len > 1 && path_tmp[path_len - 2] == ':') { if (path_len != 3) { return -1; @@ -216,10 +214,10 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path /* Resolve open_basedir to resolved_basedir */ if (expand_filepath(local_open_basedir, resolved_basedir) != NULL) { - int basedir_len = (int)strlen(basedir); + size_t basedir_len = strlen(basedir); /* Handler for basedirs that end with a / */ - resolved_basedir_len = (int)strlen(resolved_basedir); -#if defined(PHP_WIN32) || defined(NETWARE) + resolved_basedir_len = strlen(resolved_basedir); +#ifdef PHP_WIN32 if (basedir[basedir_len - 1] == PHP_DIR_SEPARATOR || basedir[basedir_len - 1] == '/') { #else if (basedir[basedir_len - 1] == PHP_DIR_SEPARATOR) { @@ -233,7 +231,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path resolved_basedir[resolved_basedir_len] = '\0'; } - resolved_name_len = (int)strlen(resolved_name); + resolved_name_len = strlen(resolved_name); if (path_tmp[path_len - 1] == PHP_DIR_SEPARATOR) { if (resolved_name[resolved_name_len - 1] != PHP_DIR_SEPARATOR) { resolved_name[resolved_name_len] = PHP_DIR_SEPARATOR; @@ -242,7 +240,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path } /* Check the path */ -#if defined(PHP_WIN32) || defined(NETWARE) +#ifdef PHP_WIN32 if (strncasecmp(resolved_basedir, resolved_name, resolved_basedir_len) == 0) { #else if (strncmp(resolved_basedir, resolved_name, resolved_basedir_len) == 0) { @@ -257,7 +255,7 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path } else { /* /openbasedir/ and /openbasedir are the same directory */ if (resolved_basedir_len == (resolved_name_len + 1) && resolved_basedir[resolved_basedir_len - 1] == PHP_DIR_SEPARATOR) { -#if defined(PHP_WIN32) || defined(NETWARE) +#ifdef PHP_WIN32 if (strncasecmp(resolved_basedir, resolved_name, resolved_name_len) == 0) { #else if (strncmp(resolved_basedir, resolved_name, resolved_name_len) == 0) { @@ -408,16 +406,14 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle) IS_ABSOLUTE_PATH(PG(doc_root), length)) { int path_len = (int)strlen(path_info); filename = emalloc(length + path_len + 2); - if (filename) { - memcpy(filename, PG(doc_root), length); - if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */ - filename[length++] = PHP_DIR_SEPARATOR; - } - if (IS_SLASH(path_info[0])) { - length--; - } - strncpy(filename + length, path_info, path_len + 1); + memcpy(filename, PG(doc_root), length); + if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */ + filename[length++] = PHP_DIR_SEPARATOR; + } + if (IS_SLASH(path_info[0])) { + length--; } + strncpy(filename + length, path_info, path_len + 1); } else { filename = SG(request_info).path_translated; } diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h index b3c4d7f3ab..5e1544c513 100644 --- a/main/fopen_wrappers.h +++ b/main/fopen_wrappers.h @@ -54,4 +54,6 @@ END_EXTERN_C() * tab-width: 4 * c-basic-offset: 4 * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ diff --git a/main/http_status_codes.h b/main/http_status_codes.h index 64306bdacb..a8417b6b89 100644 --- a/main/http_status_codes.h +++ b/main/http_status_codes.h @@ -82,3 +82,11 @@ static http_response_status_code_pair http_status_map[] = { static const size_t http_status_map_len = (sizeof(http_status_map) / sizeof(http_response_status_code_pair)) - 1; #endif /* HTTP_STATUS_CODES_H */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/internal_functions_nw.c b/main/internal_functions_nw.c deleted file mode 100644 index 54555c157a..0000000000 --- a/main/internal_functions_nw.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2017 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - | Modified for NetWare: Novell, Inc. | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes - */ -#include "php.h" -#include "php_main.h" -#include "zend_modules.h" -#include "zend_compile.h" -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> - -#include "ext/bcmath/php_bcmath.h" -#include "ext/gd/php_gd.h" -#include "ext/standard/dl.h" -#include "ext/standard/file.h" -#include "ext/standard/fsock.h" -#include "ext/standard/head.h" -#include "ext/standard/pack.h" -#include "ext/standard/php_browscap.h" -/*#include "ext/standard/php_crypt.h"*/ -#include "ext/standard/php_dir.h" -#include "ext/standard/php_filestat.h" -#include "ext/standard/php_mail.h" -/*#include "ext/standard/php_ext_syslog.h"*/ -#include "ext/standard/php_standard.h" -#include "ext/standard/php_lcg.h" -#include "ext/standard/php_array.h" -#include "ext/standard/php_assert.h" -#include "ext/calendar/php_calendar.h" -/*#include "ext/com/php_COM.h" -#include "ext/com/php_VARIANT.h"*/ -#include "ext/ftp/php_ftp.h" -#include "ext/standard/reg.h" -#include "ext/pcre/php_pcre.h" -/*#include "ext/odbc/php_odbc.h"*/ /* Commented out for now */ -#include "ext/session/php_session.h" -/*#include "ext/xml/php_xml.h" -#include "ext/wddx/php_wddx.h" -#include "ext/mysql/php_mysql.h"*/ /* Commented out for now */ -/* }}} */ - -/* {{{ php_builtin_extensions[] - */ -static zend_module_entry *php_builtin_extensions[] = { - phpext_standard_ptr, -#if HAVE_BCMATH - phpext_bcmath_ptr, -#endif - phpext_calendar_ptr, -/* COM_module_ptr,*/ - phpext_ftp_ptr, -#if defined(MBSTR_ENC_TRANS) - phpext_mbstring_ptr, -#endif -/* phpext_mysql_ptr,*/ /* Commented out for now */ -/* phpext_odbc_ptr, */ /* Commented out for now */ - phpext_pcre_ptr, - phpext_session_ptr, -/* phpext_xml_ptr, - phpext_wddx_ptr */ /* Commented out for now */ -}; -/* }}} */ - -#define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *)) - -PHPAPI int php_register_internal_extensions(void) -{ - return php_register_extensions(php_builtin_extensions, EXTCOUNT); -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/main/main.c b/main/main.c index 863daec18a..25fa644e4d 100644 --- a/main/main.c +++ b/main/main.c @@ -34,11 +34,6 @@ #include "win32/php_win32_globals.h" #include "win32/winutil.h" #include <process.h> -#elif defined(NETWARE) -#include <sys/timeval.h> -#ifdef USE_WINSOCK -#include <novsock2.h> -#endif #endif #if HAVE_SYS_TIME_H #include <sys/time.h> @@ -511,8 +506,8 @@ PHP_INI_MH(OnChangeBrowscap); * PHP_INCLUDE_PATH */ - /* Windows and Netware use the internal mail */ -#if defined(PHP_WIN32) || defined(NETWARE) + /* Windows use the internal mail */ +#if defined(PHP_WIN32) # define DEFAULT_SENDMAIL_PATH NULL #elif defined(PHP_PROG_SENDMAIL) # define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i " @@ -552,7 +547,6 @@ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("short_open_tag", DEFAULT_SHORT_OPEN_TAG, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, short_tags, zend_compiler_globals, compiler_globals) - STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals) STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals) @@ -914,7 +908,7 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ efree(docref_buf); } - if (PG(track_errors) && module_initialized && EG(valid_symbol_table) && + if (PG(track_errors) && module_initialized && EG(active) && (Z_TYPE(EG(user_error_handler)) == IS_UNDEF || !(EG(user_error_handler_error_reporting) & type))) { zval tmp; ZVAL_STRINGL(&tmp, buffer, buffer_len); @@ -1010,7 +1004,7 @@ PHPAPI void php_html_puts(const char *str, size_t size) /* {{{ php_error_cb extended error handling function */ -static ZEND_COLD void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) +static ZEND_COLD void php_error_cb(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) { char *buffer; int buffer_len, display; @@ -1241,7 +1235,7 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u return; } - if (PG(track_errors) && module_initialized && EG(valid_symbol_table)) { + if (PG(track_errors) && module_initialized && EG(active)) { zval tmp; ZVAL_STRINGL(&tmp, buffer, buffer_len); @@ -1607,6 +1601,8 @@ int php_request_startup(void) { int retval = SUCCESS; + zend_interned_strings_activate(); + #ifdef HAVE_DTRACE DTRACE_REQUEST_STARTUP(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), (char *)SAFE_FILENAME(SG(request_info).request_method)); #endif /* HAVE_DTRACE */ @@ -1685,6 +1681,8 @@ int php_request_startup(void) { int retval = SUCCESS; + zend_interned_strings_activate(); + #if PHP_SIGCHILD signal(SIGCHLD, sigchld_handler); #endif @@ -1717,6 +1715,8 @@ int php_request_startup_for_hook(void) { int retval = SUCCESS; + zend_interned_strings_activate(); + #if PHP_SIGCHLD signal(SIGCHLD, sigchld_handler); #endif @@ -1740,8 +1740,8 @@ void php_request_shutdown_for_exec(void *dummy) /* used to close fd's in the 3..255 range here, but it's problematic */ + zend_interned_strings_deactivate(); shutdown_memory_manager(1, 1); - zend_interned_strings_restore(); } /* }}} */ @@ -1784,12 +1784,12 @@ void php_request_shutdown_for_hook(void *dummy) php_shutdown_stream_hashes(); } zend_end_try(); + zend_interned_strings_deactivate(); + zend_try { shutdown_memory_manager(CG(unclean_shutdown), 0); } zend_end_try(); - zend_interned_strings_restore(); - #ifdef ZEND_SIGNALS zend_try { zend_signal_deactivate(); @@ -1805,6 +1805,8 @@ void php_request_shutdown(void *dummy) { zend_bool report_memleaks; + EG(flags) |= EG_FLAGS_IN_SHUTDOWN; + report_memleaks = PG(report_memleaks); /* EG(current_execute_data) points into nirvana and therefore cannot be safely accessed @@ -1895,7 +1897,7 @@ void php_request_shutdown(void *dummy) } zend_end_try(); /* 15. Free Willy (here be crashes) */ - zend_interned_strings_restore(); + zend_interned_strings_deactivate(); zend_try { shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0); } zend_end_try(); @@ -1946,6 +1948,7 @@ static size_t php_output_wrapper(const char *str, size_t str_length) static void core_globals_ctor(php_core_globals *core_globals) { memset(core_globals, 0, sizeof(*core_globals)); + php_startup_ticks(); } /* }}} */ #endif @@ -2052,7 +2055,7 @@ void dummy_invalid_parameter_handler( /* {{{ php_module_startup */ -int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules) +int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint32_t num_additional_modules) { zend_utility_functions zuf; zend_utility_values zuv; @@ -2060,11 +2063,10 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod char *php_os; zend_module_entry *module; -#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) +#ifdef PHP_WIN32 WORD wVersionRequested = MAKEWORD(2, 0); WSADATA wsaData; -#endif -#ifdef PHP_WIN32 + php_os = "WINNT"; old_invalid_parameter_handler = @@ -2084,7 +2086,10 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod #endif #ifdef PHP_WIN32 - php_win32_init_rng_lock(); + if (!php_win32_init_random_bytes()) { + fprintf(stderr, "\ncrypt algorithm provider initialization failed\n"); + return FAILURE; + } #endif module_shutdown = 0; @@ -2102,7 +2107,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod #ifdef ZTS ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor); - php_startup_ticks(); #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 @@ -2121,8 +2125,8 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod zuf.ticks_function = php_run_ticks; zuf.on_timeout = php_on_timeout; zuf.stream_open_function = php_stream_open_for_zend; - zuf.vspprintf_function = vspprintf; - zuf.vstrpprintf_function = vstrpprintf; + zuf.printf_to_smart_string_function = php_printf_to_smart_string; + zuf.printf_to_smart_str_function = php_printf_to_smart_str; zuf.getenv_function = sapi_getenv; zuf.resolve_path_function = php_resolve_path_for_zend; zend_startup(&zuf, NULL); @@ -2136,7 +2140,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod tzset(); #endif -#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) +#ifdef PHP_WIN32 /* start up winsock services */ if (WSAStartup(wVersionRequested, &wsaData) != 0) { php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError()); @@ -2160,6 +2164,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod #endif REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS_FAMILY", PHP_OS_FAMILY, sizeof(PHP_OS_FAMILY)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS); 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); @@ -2183,6 +2188,10 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MIN", ZEND_LONG_MIN, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", SIZEOF_ZEND_LONG, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_LONG_CONSTANT("PHP_FD_SETSIZE", FD_SETSIZE, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("PHP_FLOAT_DIG", DBL_DIG, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_DOUBLE_CONSTANT("PHP_FLOAT_EPSILON", DBL_EPSILON, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_DOUBLE_CONSTANT("PHP_FLOAT_MAX", DBL_MAX, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_DOUBLE_CONSTANT("PHP_FLOAT_MIN", DBL_MIN, CONST_PERSISTENT | CONST_CS); #ifdef PHP_WIN32 REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS); @@ -2236,7 +2245,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod zuv.html_errors = 1; zuv.import_use_extension = ".php"; - zuv.import_use_extension_length = (uint)strlen(zuv.import_use_extension); + zuv.import_use_extension_length = (uint32_t)strlen(zuv.import_use_extension); php_startup_auto_globals(); zend_set_utility_values(&zuv); php_startup_sapi_content_types(); @@ -2298,8 +2307,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod } directives[2] = { { E_DEPRECATED, - "Directive '%s' is deprecated in PHP 5.3 and greater", + "Directive '%s' is deprecated", { + "track_errors", NULL } }, @@ -2350,13 +2360,16 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod } zend_end_try(); } + virtual_cwd_deactivate(); + sapi_deactivate(); module_startup = 0; shutdown_memory_manager(1, 0); - zend_interned_strings_snapshot(); virtual_cwd_activate(); + zend_interned_strings_switch_storage(); + /* we're done */ return retval; } @@ -2392,19 +2405,19 @@ void php_module_shutdown(void) ts_free_worker_threads(); #endif -#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) - /*close winsock */ - WSACleanup(); -#endif - #ifdef PHP_WIN32 - php_win32_free_rng_lock(); + (void)php_win32_shutdown_random_bytes(); #endif sapi_flush(); zend_shutdown(); +#ifdef PHP_WIN32 + /*close winsock */ + WSACleanup(); +#endif + /* Destroys filter & transport registries too */ php_shutdown_stream_wrappers(module_number); @@ -2485,7 +2498,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file) * otherwise it will get opened and added to the included_files list in zend_execute_scripts */ if (primary_file->filename && - (primary_file->filename[0] != '-' || primary_file->filename[1] != 0) && + strcmp("Standard input code", primary_file->filename) && primary_file->opened_path == NULL && primary_file->type != ZEND_HANDLE_FILENAME ) { diff --git a/main/network.c b/main/network.c index b983045fae..763a84be94 100644 --- a/main/network.c +++ b/main/network.c @@ -32,9 +32,6 @@ # include "win32/inet.h" # define O_RDONLY _O_RDONLY # include "win32/param.h" -#elif defined(NETWARE) -#include <sys/timeval.h> -#include <sys/param.h> #else #include <sys/param.h> #endif @@ -57,17 +54,8 @@ #include <sys/poll.h> #endif -#if defined(NETWARE) -#ifdef USE_WINSOCK -#include <novsock2.h> -#else -#include <arpa/inet.h> -#include <netinet/in.h> -#include <netdb.h> -#include <sys/select.h> -#include <sys/socket.h> -#endif -#elif !defined(PHP_WIN32) + +#ifndef PHP_WIN32 #include <netinet/in.h> #include <netdb.h> #if HAVE_ARPA_INET_H @@ -81,7 +69,7 @@ int inet_aton(const char *, struct in_addr *); #include "php_network.h" -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) +#if defined(PHP_WIN32) || defined(__riscos__) #undef AF_UNIX #endif diff --git a/main/output.c b/main/output.c index bc43a93d34..3eb6ddcfd7 100644 --- a/main/output.c +++ b/main/output.c @@ -517,7 +517,7 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t output_handler, size_t chunk_size, int flags) { php_output_handler *handler; - zend_string *str = zend_string_init(name, name_len, 1); + zend_string *str = zend_string_init(name, name_len, 0); handler = php_output_handler_init(str, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL); handler->func.internal = output_handler; diff --git a/main/php.h b/main/php.h index 9b1c8b9b2b..388317ddd9 100644 --- a/main/php.h +++ b/main/php.h @@ -26,7 +26,7 @@ #include <dmalloc.h> #endif -#define PHP_API_VERSION 20160303 +#define PHP_API_VERSION 20170718 #define PHP_HAVE_STREAMS #define YYDEBUG 0 #define PHP_DEFAULT_CHARSET "UTF-8" @@ -41,13 +41,27 @@ #undef sprintf #define sprintf php_sprintf +/* Operating system family defintion */ +#ifdef PHP_WIN32 +# define PHP_OS_FAMILY "Windows" +#elif defined(BSD) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +# define PHP_OS_FAMILY "BSD" +#elif defined(__APPLE__) || defined(__MACH__) +# define PHP_OS_FAMILY "Darwin" +#elif defined(__sun__) +# define PHP_OS_FAMILY "Solaris" +#elif defined(__linux__) +# define PHP_OS_FAMILY "Linux" +#else +# define PHP_OS_FAMILY "Unknown" +#endif + /* PHP's DEBUG value must match Zend's ZEND_DEBUG value */ #undef PHP_DEBUG #define PHP_DEBUG ZEND_DEBUG #ifdef PHP_WIN32 # include "tsrm_win32.h" -# include "win95nt.h" # ifdef PHP_EXPORTS # define PHPAPI __declspec(dllexport) # else @@ -66,10 +80,51 @@ # define PHP_EOL "\n" #endif -#ifdef NETWARE -/* For php_get_uname() function */ -#define PHP_UNAME "NetWare" -#define PHP_OS PHP_UNAME +/* Windows specific defines */ +#ifdef PHP_WIN32 +# define PHP_PROG_SENDMAIL "Built in mailer" +# define HAVE_DECLARED_TIMEZONE +# define WIN32_LEAN_AND_MEAN +# define NOOPENFILE + +# include <io.h> +# include <malloc.h> +# include <direct.h> +# include <stdlib.h> +# include <stdio.h> +# include <stdarg.h> +# include <sys/types.h> +# include <process.h> + +typedef int uid_t; +typedef int gid_t; +typedef char * caddr_t; +typedef unsigned int uint; +typedef unsigned long ulong; +# if !NSAPI +typedef int pid_t; +# endif + +# ifndef PHP_DEBUG +# ifdef inline +# undef inline +# endif +# define inline __inline +# endif + +# define M_TWOPI (M_PI * 2.0) +# define off_t _off_t + +# define lstat(x, y) php_sys_lstat(x, y) +# define chdir(path) _chdir(path) +# define mkdir(a, b) _mkdir(a) +# define rmdir(a) _rmdir(a) +# define getpid _getpid +# define php_sleep(t) SleepEx(t*1000, TRUE) + +# ifndef getcwd +# define getcwd(a, b) _getcwd(a, b) +# endif #endif #if HAVE_ASSERT_H @@ -126,6 +181,8 @@ PHPAPI size_t php_strlcpy(char *dst, const char *src, size_t siz); END_EXTERN_C() #undef strlcpy #define strlcpy php_strlcpy +#define HAVE_STRLCPY 1 +#define USE_STRLCPY_PHP_IMPL 1 #endif #ifndef HAVE_STRLCAT @@ -134,6 +191,16 @@ PHPAPI size_t php_strlcat(char *dst, const char *src, size_t siz); END_EXTERN_C() #undef strlcat #define strlcat php_strlcat +#define HAVE_STRLCAT 1 +#define USE_STRLCAT_PHP_IMPL 1 +#endif + +#ifndef HAVE_EXPLICIT_BZERO +BEGIN_EXTERN_C() +PHPAPI void php_explicit_bzero(void *dst, size_t siz); +END_EXTERN_C() +#undef explicit_bzero +#define explicit_bzero php_explicit_bzero #endif #ifndef HAVE_STRTOK_R @@ -173,14 +240,6 @@ typedef unsigned int socklen_t; # endif #endif -#ifndef va_copy -# ifdef __va_copy -# define va_copy(ap1, ap2) __va_copy((ap1), (ap2)) -# else -# define va_copy(ap1, ap2) memcpy((&ap1), (&ap2), sizeof(va_list)) -# endif -#endif - #include "php_stdint.h" #include "zend_hash.h" diff --git a/main/php_compat.h b/main/php_compat.h index 7c05022212..f0b872dad0 100644 --- a/main/php_compat.h +++ b/main/php_compat.h @@ -376,3 +376,11 @@ #endif #endif +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_content_types.h b/main/php_content_types.h index 6b5387f46c..cd01fe8181 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -29,3 +29,11 @@ int php_startup_sapi_content_types(void); int php_setup_sapi_content_types(void); #endif /* PHP_CONTENT_TYPES_H */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_getopt.h b/main/php_getopt.h index 6ae23cc73f..ad240fa537 100644 --- a/main/php_getopt.h +++ b/main/php_getopt.h @@ -23,14 +23,6 @@ #include "php.h" -#ifdef NETWARE -/* -As NetWare LibC has optind and optarg macros defined in unistd.h our local variables were getting mistakenly preprocessed so undeffing optind and optarg -*/ -#undef optarg -#undef optind -#endif - /* Define structure for one recognized option (both single char and long name). * If short_open is '-' this is the last option. */ typedef struct _opt_struct { diff --git a/main/php_globals.h b/main/php_globals.h index b067805e14..d27f397da9 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -58,7 +58,6 @@ struct _php_core_globals { zend_long output_buffering; - zend_bool sql_safe_mode; zend_bool enable_dl; char *output_handler; @@ -177,4 +176,6 @@ struct _php_core_globals { * tab-width: 4 * c-basic-offset: 4 * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ diff --git a/main/php_ini.c b/main/php_ini.c index 75b1695ec4..7b0375027d 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -353,7 +353,7 @@ static void php_load_php_extension_cb(void *arg) static void php_load_zend_extension_cb(void *arg) { char *filename = *((char **) arg); - const int length = (int)strlen(filename); + const size_t length = strlen(filename); #ifndef PHP_WIN32 (void) length; @@ -362,16 +362,50 @@ static void php_load_zend_extension_cb(void *arg) if (IS_ABSOLUTE_PATH(filename, length)) { zend_load_extension(filename); } else { - char *libpath; + DL_HANDLE handle; + char *libpath; char *extension_dir = INI_STR("extension_dir"); - int extension_dir_len = (int)strlen(extension_dir); + int slash_suffix = 0; + char *err1, *err2; - if (IS_SLASH(extension_dir[extension_dir_len-1])) { - spprintf(&libpath, 0, "%s%s", extension_dir, filename); + if (extension_dir && extension_dir[0]) { + slash_suffix = IS_SLASH(extension_dir[strlen(extension_dir)-1]); + } + + /* Try as filename first */ + if (slash_suffix) { + spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */ } else { - spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); + spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */ } - zend_load_extension(libpath); + + handle = (DL_HANDLE)php_load_shlib(libpath, &err1); + if (!handle) { + /* If file does not exist, consider as extension name and build file name */ + char *orig_libpath = libpath; + + if (slash_suffix) { + spprintf(&libpath, 0, "%s" PHP_SHLIB_EXT_PREFIX "%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */ + } else { + spprintf(&libpath, 0, "%s%c" PHP_SHLIB_EXT_PREFIX "%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */ + } + + handle = (DL_HANDLE)php_load_shlib(libpath, &err2); + if (!handle) { + php_error(E_CORE_WARNING, "Failed loading Zend extension '%s' (tried: %s (%s), %s (%s))", + filename, orig_libpath, err1, libpath, err2); + efree(orig_libpath); + efree(err1); + efree(libpath); + efree(err2); + return; + } + + efree(orig_libpath); + efree(err1); + } + + zend_load_extension_handle(handle, libpath); efree(libpath); } } diff --git a/main/php_ini.h b/main/php_ini.h index 2ae90fe842..e582deff65 100644 --- a/main/php_ini.h +++ b/main/php_ini.h @@ -89,3 +89,11 @@ END_EXTERN_C() #define php_ini_string zend_ini_string #endif /* PHP_INI_H */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_main.h b/main/php_main.h index ffafaaf3bf..ff342a1f38 100644 --- a/main/php_main.h +++ b/main/php_main.h @@ -30,7 +30,7 @@ BEGIN_EXTERN_C() PHPAPI int php_request_startup(void); PHPAPI void php_request_shutdown(void *dummy); PHPAPI void php_request_shutdown_for_exec(void *dummy); -PHPAPI int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules); +PHPAPI int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint32_t num_additional_modules); PHPAPI void php_module_shutdown(void); PHPAPI void php_module_shutdown_for_exec(void); PHPAPI int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals); @@ -56,3 +56,11 @@ extern int php_shutdown_environ(void); END_EXTERN_C() #endif +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_network.h b/main/php_network.h index 5385fe13d4..ee02fd19fd 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -344,7 +344,9 @@ END_EXTERN_C() /* * Local variables: - * tab-width: 8 - * c-basic-offset: 8 + * tab-width: 4 + * c-basic-offset: 4 * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c index 9426297133..f2303882f4 100644 --- a/main/php_open_temporary_file.c +++ b/main/php_open_temporary_file.c @@ -30,13 +30,6 @@ #define O_RDONLY _O_RDONLY #include "win32/param.h" #include "win32/winutil.h" -#elif defined(NETWARE) -#ifdef USE_WINSOCK -#include <novsock2.h> -#else -#include <sys/socket.h> -#endif -#include <sys/param.h> #else #include <sys/param.h> #include <sys/socket.h> @@ -121,7 +114,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st } #ifdef PHP_WIN32 - if (!php_win32_check_trailing_space(pfx, (const int)strlen(pfx))) { + if (!php_win32_check_trailing_space(pfx, strlen(pfx))) { SetLastError(ERROR_INVALID_NAME); return -1; } diff --git a/main/php_open_temporary_file.h b/main/php_open_temporary_file.h index 0a9b257150..fbafb333ed 100644 --- a/main/php_open_temporary_file.h +++ b/main/php_open_temporary_file.h @@ -32,3 +32,11 @@ PHPAPI const char *php_get_temporary_directory(void); END_EXTERN_C() #endif /* PHP_OPEN_TEMPORARY_FILE_H */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_output.h b/main/php_output.h index 03bd6cca1d..6c8d50f367 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -94,8 +94,8 @@ typedef struct _php_output_buffer { char *data; size_t size; size_t used; - uint free:1; - uint _reserved:31; + uint32_t free:1; + uint32_t _reserved:31; } php_output_buffer; typedef struct _php_output_context { diff --git a/main/php_reentrancy.h b/main/php_reentrancy.h index 86f402d6cc..f66f3c5e3a 100644 --- a/main/php_reentrancy.h +++ b/main/php_reentrancy.h @@ -131,3 +131,11 @@ void reentrancy_shutdown(void); #endif #endif +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_scandir.c b/main/php_scandir.c index b56018aa7d..2bfecee3ae 100644 --- a/main/php_scandir.c +++ b/main/php_scandir.c @@ -38,9 +38,7 @@ #endif #include <stdlib.h> -#ifndef NETWARE #include <search.h> -#endif #endif /* HAVE_SCANDIR */ diff --git a/main/php_scandir.h b/main/php_scandir.h index 3e67e74820..2e8773b8b1 100644 --- a/main/php_scandir.h +++ b/main/php_scandir.h @@ -52,3 +52,11 @@ PHPAPI int php_alphasort(const struct dirent **a, const struct dirent **b); #endif #endif /* PHP_SCANDIR_H */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_sprintf.c b/main/php_sprintf.c index c0dae7af2d..60ad09c0ac 100644 --- a/main/php_sprintf.c +++ b/main/php_sprintf.c @@ -12,7 +12,7 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Jaakko Hyvätti <jaakko.hyvatti@iki.fi> | + | Author: Jaakko Hyvätti <jaakko.hyvatti@iki.fi> | +----------------------------------------------------------------------+ */ diff --git a/main/php_streams.h b/main/php_streams.h index d6e627808d..d10d087fb4 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -197,22 +197,26 @@ struct _php_stream { void *wrapperthis; /* convenience pointer for a instance of a wrapper */ zval wrapperdata; /* fgetwrapperdata retrieves this */ - int fgetss_state; /* for fgetss to handle multiline tags */ - int is_persistent; - char mode[16]; /* "rwb" etc. ala stdio */ - zend_resource *res; /* used for auto-cleanup */ - int in_free; /* to prevent recursion during free */ + uint8_t is_persistent:1; + uint8_t in_free:2; /* to prevent recursion during free */ + uint8_t eof:1; + uint8_t __exposed:1; /* non-zero if exposed as a zval somewhere */ + /* so we know how to clean it up correctly. This should be set to * PHP_STREAM_FCLOSE_XXX as appropriate */ - int fclose_stdiocast; + uint8_t fclose_stdiocast:2; + + uint8_t fgetss_state; /* for fgetss to handle multiline tags */ + + char mode[16]; /* "rwb" etc. ala stdio */ + + uint32_t flags; /* PHP_STREAM_FLAG_XXX */ + + zend_resource *res; /* used for auto-cleanup */ FILE *stdiocast; /* cache this, otherwise we might leak! */ - int __exposed; /* non-zero if exposed as a zval somewhere */ char *orig_path; zend_resource *ctx; - int flags; /* PHP_STREAM_FLAG_XXX */ - - int eof; /* buffer */ zend_off_t position; /* of underlying stream */ @@ -226,7 +230,7 @@ struct _php_stream { #if ZEND_DEBUG const char *open_filename; - uint open_lineno; + uint32_t open_lineno; #endif struct _php_stream *enclosing_stream; /* this is a private stream owned by enclosing_stream */ @@ -249,11 +253,11 @@ END_EXTERN_C() #define php_stream_get_resource_id(stream) ((php_stream *)(stream))->res->handle /* use this to tell the stream that it is OK if we don't explicitly close it */ -#define php_stream_auto_cleanup(stream) { (stream)->__exposed++; } +#define php_stream_auto_cleanup(stream) { (stream)->__exposed = 1; } /* use this to assign the stream to a zval and tell the stream that is * has been exported to the engine; it will expect to be closed automatically * when the resources are auto-destructed */ -#define php_stream_to_zval(stream, zval) { ZVAL_RES(zval, (stream)->res); (stream)->__exposed++; } +#define php_stream_to_zval(stream, zval) { ZVAL_RES(zval, (stream)->res); (stream)->__exposed = 1; } #define php_stream_from_zval(xstr, pzval) do { \ if (((xstr) = (php_stream*)zend_fetch_resource2_ex((pzval), \ diff --git a/main/php_syslog.h b/main/php_syslog.h index 33f52a336f..be68cc499a 100644 --- a/main/php_syslog.h +++ b/main/php_syslog.h @@ -50,3 +50,11 @@ #endif #endif +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_ticks.h b/main/php_ticks.h index b807b3e9ef..5df885473d 100644 --- a/main/php_ticks.h +++ b/main/php_ticks.h @@ -38,4 +38,6 @@ END_EXTERN_C() * tab-width: 4 * c-basic-offset: 4 * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ diff --git a/main/php_variables.c b/main/php_variables.c index 69fe2c24f6..1052e16edf 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -49,7 +49,13 @@ PHPAPI void php_register_variable_safe(char *var, char *strval, size_t str_len, assert(strval != NULL); /* Prepare value */ - ZVAL_NEW_STR(&new_entry, zend_string_init(strval, str_len, 0)); + if (str_len == 0) { + ZVAL_EMPTY_STRING(&new_entry); + } else if (str_len == 1) { + ZVAL_INTERNED_STR(&new_entry, ZSTR_CHAR((zend_uchar)*strval)); + } else { + ZVAL_NEW_STR(&new_entry, zend_string_init(strval, str_len, 0)); + } php_register_variable_ex(var, &new_entry, track_vars_array); } @@ -452,7 +458,7 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data) switch (arg) { case PARSE_GET: case PARSE_STRING: - separator = (char *) estrdup(PG(arg_separator).input); + separator = PG(arg_separator).input; break; case PARSE_COOKIE: separator = ";\0"; @@ -507,10 +513,6 @@ next_cookie: var = php_strtok_r(NULL, separator, &strtok_buf); } - if (arg != PARSE_COOKIE) { - efree(separator); - } - if (free_buffer) { efree(res); } @@ -542,7 +544,7 @@ void _php_import_environment_variables(zval *array_ptr) } } -zend_bool php_std_auto_global_callback(char *name, uint name_len) +zend_bool php_std_auto_global_callback(char *name, uint32_t name_len) { zend_printf("%s\n", name); return 0; /* don't rearm */ @@ -610,7 +612,7 @@ PHPAPI void php_build_argv(char *s, zval *track_vars_array) zend_hash_str_update(Z_ARRVAL_P(track_vars_array), "argv", sizeof("argv")-1, &arr); zend_hash_str_update(Z_ARRVAL_P(track_vars_array), "argc", sizeof("argc")-1, &argc); } - zval_ptr_dtor(&arr); + zval_ptr_dtor_nogc(&arr); } /* }}} */ @@ -801,6 +803,11 @@ static zend_bool php_auto_globals_create_server(zend_string *name) zend_hash_update(&EG(symbol_table), name, &PG(http_globals)[TRACK_VARS_SERVER]); Z_ADDREF(PG(http_globals)[TRACK_VARS_SERVER]); + /* TODO: TRACK_VARS_SERVER is modified in a number of places (e.g. phar) past this point, + * where rc>1 due to the $_SERVER global. Ideally this shouldn't happen, but for now we + * ignore this issue, as it would probably require larger changes. */ + HT_ALLOW_COW_VIOLATION(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])); + return 0; /* don't rearm */ } diff --git a/main/php_variables.h b/main/php_variables.h index af7254b020..5fa38fa00b 100644 --- a/main/php_variables.h +++ b/main/php_variables.h @@ -48,3 +48,11 @@ END_EXTERN_C() #define NUM_TRACK_VARS 6 #endif /* PHP_VARIABLES_H */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/php_version.h b/main/php_version.h index 252097d549..62cdcfceda 100644 --- a/main/php_version.h +++ b/main/php_version.h @@ -1,8 +1,8 @@ /* automatically generated by configure */ -/* edit configure.in to change version number */ +/* edit configure.ac to change version number */ #define PHP_MAJOR_VERSION 7 -#define PHP_MINOR_VERSION 1 -#define PHP_RELEASE_VERSION 9 +#define PHP_MINOR_VERSION 2 +#define PHP_RELEASE_VERSION 0 #define PHP_EXTRA_VERSION "-dev" -#define PHP_VERSION "7.1.9-dev" -#define PHP_VERSION_ID 70109 +#define PHP_VERSION "7.2.0-dev" +#define PHP_VERSION_ID 70200 diff --git a/main/rfc1867.c b/main/rfc1867.c index 264b234aa3..74f47f63a2 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -33,7 +33,7 @@ #include "php_variables.h" #include "rfc1867.h" #include "ext/standard/php_string.h" -#include "ext/standard/php_smart_string.h" +#include "zend_smart_string.h" #if defined(PHP_WIN32) && !defined(HAVE_ATOLL) # define atoll(s) _atoi64(s) diff --git a/main/rfc1867.h b/main/rfc1867.h index 637c325309..5dc7926db2 100644 --- a/main/rfc1867.h +++ b/main/rfc1867.h @@ -89,3 +89,11 @@ SAPI_API void php_rfc1867_set_multibyte_callbacks( php_rfc1867_basename_t basename); #endif /* RFC1867_H */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/main/snprintf.h b/main/snprintf.h index 7abf55643e..021629681d 100644 --- a/main/snprintf.h +++ b/main/snprintf.h @@ -178,4 +178,6 @@ PHPAPI char * ap_php_conv_p2(u_wide_int num, int nbits, * tab-width: 4 * c-basic-offset: 4 * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ diff --git a/main/spprintf.c b/main/spprintf.c index c8ec27dfcc..dd53fcd764 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -117,7 +117,7 @@ #define EXPONENT_LENGTH 10 #include "zend_smart_str.h" -#include "ext/standard/php_smart_string.h" +#include "zend_smart_string.h" /* {{{ macros */ @@ -138,7 +138,6 @@ } while (0); #define PAD_CHAR(xbuf, ch, count, is_char) do { \ - size_t newlen; \ if ((is_char)) { \ smart_string_alloc(((smart_string *)(xbuf)), (count), 0); \ memset(((smart_string *)(xbuf))->c + ((smart_string *)(xbuf))->len, (ch), (count)); \ @@ -828,76 +827,15 @@ skip_output: } /* }}} */ -/* - * This is the general purpose conversion function. - */ -PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) /* {{{ */ +PHPAPI void php_printf_to_smart_string(smart_string *buf, const char *format, va_list ap) /* {{{ */ { - smart_string buf = {0}; - - /* since there are places where (v)spprintf called without checking for null, - a bit of defensive coding here */ - if(!pbuf) { - return 0; - } - xbuf_format_converter(&buf, 1, format, ap); - - if (max_len && buf.len > max_len) { - buf.len = max_len; - } - - smart_string_0(&buf); - - if (buf.c) { - *pbuf = buf.c; - return buf.len; - } else { - *pbuf = estrndup("", 0); - return 0; - } + xbuf_format_converter(buf, 1, format, ap); } /* }}} */ -PHPAPI size_t spprintf(char **pbuf, size_t max_len, const char *format, ...) /* {{{ */ +PHPAPI void php_printf_to_smart_str(smart_str *buf, const char *format, va_list ap) /* {{{ */ { - size_t cc; - va_list ap; - - va_start(ap, format); - cc = vspprintf(pbuf, max_len, format, ap); - va_end(ap); - return (cc); -} -/* }}} */ - -PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) /* {{{ */ -{ - smart_str buf = {0}; - - xbuf_format_converter(&buf, 0, format, ap); - - if (!buf.s) { - return ZSTR_EMPTY_ALLOC(); - } - - if (max_len && ZSTR_LEN(buf.s) > max_len) { - ZSTR_LEN(buf.s) = max_len; - } - - smart_str_0(&buf); - return buf.s; -} -/* }}} */ - -PHPAPI zend_string *strpprintf(size_t max_len, const char *format, ...) /* {{{ */ -{ - va_list ap; - zend_string *str; - - va_start(ap, format); - str = vstrpprintf(max_len, format, ap); - va_end(ap); - return str; + xbuf_format_converter(buf, 0, format, ap); } /* }}} */ diff --git a/main/spprintf.h b/main/spprintf.h index 2a8f9aeb8e..597d95b092 100644 --- a/main/spprintf.h +++ b/main/spprintf.h @@ -16,36 +16,23 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - -/* - -The pbuf parameter of all spprintf version receives a pointer to the allocated -buffer. This buffer must be freed manually after usage using efree() function. -The buffer will always be terminated by a zero character. When pbuf is NULL -the function can be used to calculate the required size of the buffer but for -that purpose snprintf is faster. When both pbuf and the return value are 0 -than you are out of memory. - -There is also snprintf: See difference explained in snprintf.h - -*/ - #ifndef SPPRINTF_H #define SPPRINTF_H #include "snprintf.h" +#include "zend_smart_str_public.h" +#include "zend_smart_string_public.h" BEGIN_EXTERN_C() -PHPAPI size_t spprintf( char **pbuf, size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); - -PHPAPI size_t vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 3, 0); - -PHPAPI zend_string *vstrpprintf(size_t max_len, const char *format, va_list ap) PHP_ATTRIBUTE_FORMAT(printf, 2, 0); - -PHPAPI zend_string *strpprintf(size_t max_len, const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3); +PHPAPI void php_printf_to_smart_string(smart_string *buf, const char *format, va_list ap); +PHPAPI void php_printf_to_smart_str(smart_str *buf, const char *format, va_list ap); END_EXTERN_C() +#define spprintf zend_spprintf +#define strpprintf zend_strpprintf +#define vspprintf zend_vspprintf +#define vstrpprintf zend_vstrpprintf + #endif /* SNPRINTF_H */ /* @@ -53,4 +40,6 @@ END_EXTERN_C() * tab-width: 4 * c-basic-offset: 4 * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 */ diff --git a/main/streams/filter.c b/main/streams/filter.c index 6d38869556..bb167c4409 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -68,28 +68,17 @@ PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern /* Buckets */ -PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent) +PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, uint8_t own_buf, uint8_t buf_persistent) { int is_persistent = php_stream_is_persistent(stream); php_stream_bucket *bucket; bucket = (php_stream_bucket*)pemalloc(sizeof(php_stream_bucket), is_persistent); - - if (bucket == NULL) { - return NULL; - } - bucket->next = bucket->prev = NULL; if (is_persistent && !buf_persistent) { /* all data in a persistent bucket must also be persistent */ bucket->buf = pemalloc(buflen, 1); - - if (bucket->buf == NULL) { - pefree(bucket, 1); - return NULL; - } - memcpy(bucket->buf, buf, buflen); bucket->buflen = buflen; bucket->own_buf = 1; @@ -141,10 +130,6 @@ PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **le *left = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent); *right = (php_stream_bucket*)pecalloc(1, sizeof(php_stream_bucket), in->is_persistent); - if (*left == NULL || *right == NULL) { - goto exit_fail; - } - (*left)->buf = pemalloc(length, in->is_persistent); (*left)->buflen = length; memcpy((*left)->buf, in->buf, length); @@ -160,21 +145,6 @@ PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **le (*right)->is_persistent = in->is_persistent; return SUCCESS; - -exit_fail: - if (*right) { - if ((*right)->buf) { - pefree((*right)->buf, in->is_persistent); - } - pefree(*right, in->is_persistent); - } - if (*left) { - if ((*left)->buf) { - pefree((*left)->buf, in->is_persistent); - } - pefree(*left, in->is_persistent); - } - return FAILURE; } PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket) @@ -247,7 +217,7 @@ PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket) * match. If that fails, we try "convert.charset.*", then "convert.*" * This means that we don't need to clog up the hashtable with a zillion * charsets (for example) but still be able to provide them all as filters */ -PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent) +PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent) { HashTable *filter_hash = (FG(stream_filters) ? FG(stream_filters) : &stream_filters_hash); php_stream_filter_factory *factory = NULL; @@ -290,7 +260,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval return filter; } -PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC) +PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, uint8_t persistent STREAMS_DC) { php_stream_filter *filter; @@ -358,7 +328,7 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea php_stream_bucket_append(brig_inp, bucket); status = filter->fops->filter(stream, filter, brig_inp, brig_outp, &consumed, PSFS_FLAG_NORMAL); - if (stream->readpos + consumed > (uint)stream->writepos) { + if (stream->readpos + consumed > (uint32_t)stream->writepos) { /* No behaving filter should cause this. */ status = PSFS_ERR_FATAL; } diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 1288fa6bad..1350962837 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -116,7 +116,7 @@ static void php_glob_stream_path_split(glob_s_t *pglob, const char *path, int ge if ((pos = strrchr(path, '/')) != NULL) { path = pos+1; } -#if defined(PHP_WIN32) || defined(NETWARE) +#ifdef PHP_WIN32 if ((pos = strrchr(path, '\\')) != NULL) { path = pos+1; } @@ -240,7 +240,7 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, const cha if ((tmp = strrchr(pos, '/')) != NULL) { pos = tmp+1; } -#if defined(PHP_WIN32) || defined(NETWARE) +#ifdef PHP_WIN32 if ((tmp = strrchr(pos, '\\')) != NULL) { pos = tmp+1; } diff --git a/main/streams/memory.c b/main/streams/memory.c index 39578dcffa..7af87c7efb 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -62,12 +62,8 @@ static size_t php_stream_memory_write(php_stream *stream, const char *buf, size_ } else { tmp = erealloc(ms->data, ms->fpos + count); } - if (!tmp) { - count = ms->fsize - ms->fpos + 1; - } else { - ms->data = tmp; - ms->fsize = ms->fpos + count; - } + ms->data = tmp; + ms->fsize = ms->fpos + count; } if (!ms->data) count = 0; @@ -214,17 +210,9 @@ static int php_stream_memory_stat(php_stream *stream, php_stream_statbuf *ssb) / ssb->sb.st_size = ms->fsize; ssb->sb.st_mode |= S_IFREG; /* regular file */ - -#ifdef NETWARE - ssb->sb.st_mtime.tv_sec = timestamp; - ssb->sb.st_atime.tv_sec = timestamp; - ssb->sb.st_ctime.tv_sec = timestamp; -#else ssb->sb.st_mtime = timestamp; ssb->sb.st_atime = timestamp; ssb->sb.st_ctime = timestamp; -#endif - ssb->sb.st_nlink = 1; ssb->sb.st_rdev = -1; /* this is only for APC, so use /dev/null device - no chance of conflict there! */ @@ -630,10 +618,10 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con php_stream *stream; php_stream_temp_data *ts; char *comma, *semi, *sep, *key; - size_t mlen, dlen, plen, vlen; + size_t mlen, dlen, plen, vlen, ilen; zend_off_t newoffs; zval meta; - int base64 = 0, ilen; + int base64 = 0; zend_string *base64_comma = NULL; ZVAL_NULL(&meta); @@ -732,11 +720,11 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con return NULL; } comma = ZSTR_VAL(base64_comma); - ilen = (int)ZSTR_LEN(base64_comma); + ilen = ZSTR_LEN(base64_comma); } else { comma = estrndup(comma, dlen); dlen = php_url_decode(comma, dlen); - ilen = (int)dlen; + ilen = dlen; } if ((stream = php_stream_temp_create_rel(0, ~0u)) != NULL) { diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h index 3b9ca16145..c109ca9993 100644 --- a/main/streams/php_stream_filter_api.h +++ b/main/streams/php_stream_filter_api.h @@ -48,8 +48,8 @@ struct _php_stream_bucket { char *buf; size_t buflen; /* if non-zero, buf should be pefreed when the bucket is destroyed */ - int own_buf; - int is_persistent; + uint8_t own_buf; + uint8_t is_persistent; /* destroy this struct when refcount falls to zero */ int refcount; @@ -67,7 +67,7 @@ typedef enum { /* Buckets API. */ BEGIN_EXTERN_C() -PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent); +PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, uint8_t own_buf, uint8_t buf_persistent); PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length); PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket); #define php_stream_bucket_addref(bucket) (bucket)->refcount++ @@ -131,7 +131,7 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish); PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor); PHPAPI void php_stream_filter_free(php_stream_filter *filter); -PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC); +PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, uint8_t persistent STREAMS_DC); END_EXTERN_C() #define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC) #define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC) @@ -142,14 +142,14 @@ END_EXTERN_C() #define php_stream_is_filtered(stream) ((stream)->readfilters.head || (stream)->writefilters.head) typedef struct _php_stream_filter_factory { - php_stream_filter *(*create_filter)(const char *filtername, zval *filterparams, int persistent); + php_stream_filter *(*create_filter)(const char *filtername, zval *filterparams, uint8_t persistent); } php_stream_filter_factory; BEGIN_EXTERN_C() PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory); PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern); PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory); -PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent); +PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent); END_EXTERN_C() /* diff --git a/main/streams/php_stream_transport.h b/main/streams/php_stream_transport.h index 07598f3773..bc9845e14d 100644 --- a/main/streams/php_stream_transport.h +++ b/main/streams/php_stream_transport.h @@ -172,8 +172,8 @@ typedef enum { STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT = (1 << 3 | 1), STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT = (1 << 4 | 1), STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT = (1 << 5 | 1), - /* tls now equates only to the specific TLSv1 method for BC with pre-5.6 */ - STREAM_CRYPTO_METHOD_TLS_CLIENT = (1 << 3 | 1), + /* TLS equates to TLS_ANY as of PHP 7.2 */ + STREAM_CRYPTO_METHOD_TLS_CLIENT = ((1 << 3) | (1 << 4) | (1 << 5) | 1), STREAM_CRYPTO_METHOD_TLS_ANY_CLIENT = ((1 << 3) | (1 << 4) | (1 << 5) | 1), STREAM_CRYPTO_METHOD_ANY_CLIENT = ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | 1), STREAM_CRYPTO_METHOD_SSLv2_SERVER = (1 << 1), @@ -183,8 +183,8 @@ typedef enum { STREAM_CRYPTO_METHOD_TLSv1_0_SERVER = (1 << 3), STREAM_CRYPTO_METHOD_TLSv1_1_SERVER = (1 << 4), STREAM_CRYPTO_METHOD_TLSv1_2_SERVER = (1 << 5), - /* tls equates only to the specific TLSv1 method for BC with pre-5.6 */ - STREAM_CRYPTO_METHOD_TLS_SERVER = (1 << 3), + /* TLS equates to TLS_ANY as of PHP 7.2 */ + STREAM_CRYPTO_METHOD_TLS_SERVER = ((1 << 3) | (1 << 4) | (1 << 5)), STREAM_CRYPTO_METHOD_TLS_ANY_SERVER = ((1 << 3) | (1 << 4) | (1 << 5)), STREAM_CRYPTO_METHOD_ANY_SERVER = ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5)) } php_stream_xport_crypt_method_t; diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 25eacceec5..a5429138f3 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -51,7 +51,7 @@ #define php_stream_fopen_from_file_int(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_CC) #define php_stream_fopen_from_file_int_rel(file, mode) _php_stream_fopen_from_file_int((file), (mode) STREAMS_REL_CC) -#if !defined(WINDOWS) && !defined(NETWARE) +#ifndef PHP_WIN32 extern int php_get_uid_by_name(const char *name, uid_t *uid); extern int php_get_gid_by_name(const char *name, gid_t *gid); #endif @@ -1007,7 +1007,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen /* fall through */ case PHP_STREAM_PERSISTENT_FAILURE: - efree(persistent_id);; + efree(persistent_id); return ret; } } @@ -1139,11 +1139,11 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f } #ifdef PHP_WIN32 - if (!php_win32_check_trailing_space(url_from, (int)strlen(url_from))) { + if (!php_win32_check_trailing_space(url_from, strlen(url_from))) { php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to); return 0; } - if (!php_win32_check_trailing_space(url_to, (int)strlen(url_to))) { + if (!php_win32_check_trailing_space(url_to, strlen(url_to))) { php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to); return 0; } @@ -1170,7 +1170,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f zend_stat_t sb; if (php_copy_file(url_from, url_to) == SUCCESS) { if (VCWD_STAT(url_from, &sb) == 0) { -# if !defined(TSRM_WIN32) && !defined(NETWARE) +# ifndef TSRM_WIN32 if (VCWD_CHMOD(url_to, sb.st_mode)) { if (errno == EPERM) { php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno)); @@ -1229,8 +1229,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ char *e; zend_stat_t sb; - int dir_len = (int)strlen(dir); - int offset = 0; + size_t dir_len = strlen(dir), offset = 0; char buf[MAXPATHLEN]; if (!expand_filepath_with_mode(dir, buf, NULL, 0, CWD_EXPAND )) { @@ -1311,7 +1310,7 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i } #ifdef PHP_WIN32 - if (!php_win32_check_trailing_space(url, (int)strlen(url))) { + if (!php_win32_check_trailing_space(url, strlen(url))) { php_error_docref1(NULL, url, E_WARNING, "%s", strerror(ENOENT)); return 0; } @@ -1331,18 +1330,15 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context) { struct utimbuf *newtime; -#if !defined(WINDOWS) && !defined(NETWARE) +#ifndef PHP_WIN32 uid_t uid; gid_t gid; #endif mode_t mode; int ret = 0; -#ifdef PHP_WIN32 - int url_len = (int)strlen(url); -#endif #ifdef PHP_WIN32 - if (!php_win32_check_trailing_space(url, url_len)) { + if (!php_win32_check_trailing_space(url, strlen(url))) { php_error_docref1(NULL, url, E_WARNING, "%s", strerror(ENOENT)); return 0; } @@ -1370,7 +1366,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url ret = VCWD_UTIME(url, newtime); break; -#if !defined(WINDOWS) && !defined(NETWARE) +#ifndef PHP_WIN32 case PHP_STREAM_META_OWNER_NAME: case PHP_STREAM_META_OWNER: if(option == PHP_STREAM_META_OWNER_NAME) { @@ -1441,7 +1437,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char const char *ptr; char trypath[MAXPATHLEN]; php_stream *stream; - int filename_length; + size_t filename_length; zend_string *exec_filename; if (opened_path) { @@ -1452,7 +1448,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char return NULL; } - filename_length = (int)strlen(filename); + filename_length = strlen(filename); #ifndef PHP_WIN32 (void) filename_length; #endif diff --git a/main/streams/streams.c b/main/streams/streams.c index 93ac083559..dab8505d41 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -405,10 +405,9 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options) /* {{{ */ php_stream *enclosing_stream = stream->enclosing_stream; stream->enclosing_stream = NULL; /* we force PHP_STREAM_CALL_DTOR because that's from where the - * enclosing stream can free this stream. We remove rsrc_dtor because - * we want the enclosing stream to be deleted from the resource list */ + * enclosing stream can free this stream. */ return php_stream_free(enclosing_stream, - (close_options | PHP_STREAM_FREE_CALL_DTOR) & ~PHP_STREAM_FREE_RSRC_DTOR); + (close_options | PHP_STREAM_FREE_CALL_DTOR | PHP_STREAM_FREE_KEEP_RSRC) & ~PHP_STREAM_FREE_RSRC_DTOR); } /* if we are releasing the stream only (and preserving the underlying handle), @@ -502,43 +501,13 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov /* we don't work with *stream but need its value for comparison */ zend_hash_apply_with_argument(&EG(persistent_list), _php_stream_free_persistent, stream); } -#if ZEND_DEBUG - if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) && (stream->__exposed == 0) && (EG(error_reporting) & E_WARNING)) { - /* it leaked: Lets deliberately NOT pefree it so that the memory manager shows it - * as leaked; it will log a warning, but lets help it out and display what kind - * of stream it was. */ - if (!CG(unclean_shutdown)) { - char *leakinfo; - spprintf(&leakinfo, 0, __FILE__ "(%d) : Stream of type '%s' %p (path:%s) was not closed\n", __LINE__, stream->ops->label, stream, stream->orig_path); - - if (stream->orig_path) { - pefree(stream->orig_path, stream->is_persistent); - stream->orig_path = NULL; - } -# if defined(PHP_WIN32) - OutputDebugString(leakinfo); -# else - fprintf(stderr, "%s", leakinfo); -# endif - efree(leakinfo); - } - } else { - if (stream->orig_path) { - pefree(stream->orig_path, stream->is_persistent); - stream->orig_path = NULL; - } - - pefree(stream, stream->is_persistent); - } -#else if (stream->orig_path) { pefree(stream->orig_path, stream->is_persistent); stream->orig_path = NULL; } pefree(stream, stream->is_persistent); -#endif } if (context) { @@ -1661,7 +1630,7 @@ int php_init_stream_wrappers(int module_number) return (php_stream_xport_register("tcp", php_stream_generic_socket_factory) == SUCCESS && php_stream_xport_register("udp", php_stream_generic_socket_factory) == SUCCESS -#if defined(AF_UNIX) && !(defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE)) +#if defined(AF_UNIX) && !(defined(PHP_WIN32) || defined(__riscos__)) && php_stream_xport_register("unix", php_stream_generic_socket_factory) == SUCCESS && @@ -1706,7 +1675,7 @@ PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrap return FAILURE; } - return zend_hash_str_add_ptr(&url_stream_wrappers_hash, protocol, protocol_len, wrapper) ? SUCCESS : FAILURE; + return zend_hash_add_ptr(&url_stream_wrappers_hash, zend_string_init_interned(protocol, protocol_len, 1), wrapper) ? SUCCESS : FAILURE; } PHPAPI int php_unregister_url_stream_wrapper(const char *protocol) diff --git a/main/streams/userspace.c b/main/streams/userspace.c index c6e4358dc1..b5061514f4 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -864,15 +864,9 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb) STAT_PROP_ENTRY(rdev); #endif STAT_PROP_ENTRY(size); -#ifdef NETWARE - STAT_PROP_ENTRY_EX(atime, atime.tv_sec); - STAT_PROP_ENTRY_EX(mtime, mtime.tv_sec); - STAT_PROP_ENTRY_EX(ctime, ctime.tv_sec); -#else STAT_PROP_ENTRY(atime); STAT_PROP_ENTRY(mtime); STAT_PROP_ENTRY(ctime); -#endif #ifdef HAVE_ST_BLKSIZE STAT_PROP_ENTRY(blksize); #endif diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index e496a2d7fd..8efc4cdbc3 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -23,7 +23,7 @@ #include "streams/php_streams_int.h" #include "php_network.h" -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) +#if defined(PHP_WIN32) || defined(__riscos__) # undef AF_UNIX #endif diff --git a/main/strlcat.c b/main/strlcat.c index 30dfd0f8a9..d3c8972d68 100644 --- a/main/strlcat.c +++ b/main/strlcat.c @@ -20,9 +20,9 @@ #include "php.h" -#ifndef HAVE_STRLCAT +#ifdef USE_STRLCAT_PHP_IMPL -/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ +/* $OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; +static char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -69,29 +69,34 @@ PHPAPI size_t php_strlcat(dst, src, siz) const char *src; size_t siz; { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + const char *d = dst; + const char *s = src; + size_t n = siz; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end */ - while (*d != '\0' && n-- != 0) - d++; - dlen = d - dst; + while (n-- != 0 && *dst != '\0') + dst++; + dlen = (uintptr_t)dst - (uintptr_t)d; n = siz - dlen; - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; n--; } - s++; + src++; } - *d = '\0'; + *dst = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + /* + * Cast pointers to unsigned type before calculation, to avoid signed + * overflow when the string ends where the MSB has changed. + * Return value does not include NUL. + */ + return(dlen + ((uintptr_t)src - (uintptr_t)s)); } #endif /* !HAVE_STRLCAT */ diff --git a/main/strlcpy.c b/main/strlcpy.c index 8d7b2652ea..548dd9410b 100644 --- a/main/strlcpy.c +++ b/main/strlcpy.c @@ -20,9 +20,9 @@ #include "php.h" -#ifndef HAVE_STRLCPY +#ifdef USE_STRLCPY_PHP_IMPL -/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ +/* $OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; +static char *rcsid = "$OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -68,27 +68,31 @@ PHPAPI size_t php_strlcpy(dst, src, siz) const char *src; size_t siz; { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + const char *s = src; + size_t n = siz; /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) + if (n != 0) { + while (--n != 0) { + if ((*dst++ = *src++) == 0) break; - } while (--n != 0); + } } /* Not enough room in dst, add NUL and traverse rest of src */ if (n == 0) { if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) ; } - return(s - src - 1); /* count does not include NUL */ + /* + * Cast pointers to unsigned type before calculation, to avoid signed + * overflow when the string ends where the MSB has changed. + * Return value does not include NUL. + */ + return((uintptr_t)src - (uintptr_t)s - 1); } #endif /* !HAVE_STRLCPY */ diff --git a/main/win95nt.h b/main/win95nt.h deleted file mode 100644 index 3b0bbc866e..0000000000 --- a/main/win95nt.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2017 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Defines and types for Windows 95/NT */ -#define HAVE_DECLARED_TIMEZONE -#define WIN32_LEAN_AND_MEAN -#include <io.h> -#include <malloc.h> -#include <direct.h> -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <sys/types.h> -#include <process.h> - -typedef int uid_t; -typedef int gid_t; -typedef char * caddr_t; -#define lstat(x, y) php_sys_lstat(x, y) -#define _IFIFO 0010000 /* fifo */ -#define _IFBLK 0060000 /* block special */ -#define _IFLNK 0120000 /* symbolic link */ -#define S_IFIFO _IFIFO -#define S_IFBLK _IFBLK -#ifndef S_IFLNK -# define S_IFLNK _IFLNK -#endif -#define chdir(path) _chdir(path) -#define mkdir(a, b) _mkdir(a) -#define rmdir(a) _rmdir(a) -#define getpid _getpid -#define php_sleep(t) SleepEx(t*1000, TRUE) -#ifndef getcwd -# define getcwd(a, b) _getcwd(a, b) -#endif -#define off_t _off_t -typedef unsigned int uint; -typedef unsigned long ulong; -#if !NSAPI -typedef int pid_t; -#endif - -/* missing in vc5 math.h */ -#define M_PI 3.14159265358979323846 -#define M_TWOPI (M_PI * 2.0) -#define M_PI_2 1.57079632679489661923 -#ifndef M_PI_4 -#define M_PI_4 0.78539816339744830962 -#endif - -#if !defined(PHP_DEBUG) -#ifdef inline -#undef inline -#endif -#define inline __inline -#endif - -/* General Windows stuff */ -#ifndef WINDOWS -# define WINDOWS 1 -#endif - - -/* Prevent use of VC5 OpenFile function */ -#define NOOPENFILE - -/* sendmail is built-in */ -#ifdef PHP_PROG_SENDMAIL -#undef PHP_PROG_SENDMAIL -#define PHP_PROG_SENDMAIL "Built in mailer" -#endif |