summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/SAPI.c9
-rw-r--r--main/SAPI.h27
-rw-r--r--main/fastcgi.c11
-rw-r--r--main/fastcgi.h4
-rw-r--r--main/fopen_wrappers.h11
-rw-r--r--main/getopt.c2
-rw-r--r--main/main.c87
-rw-r--r--main/network.c23
-rw-r--r--main/php.h25
-rw-r--r--main/php_globals.h1
-rw-r--r--main/php_ini.c2
-rw-r--r--main/php_network.h5
-rw-r--r--main/php_open_temporary_file.c63
-rw-r--r--main/php_open_temporary_file.h5
-rw-r--r--main/php_output.h4
-rw-r--r--main/php_variables.c22
-rw-r--r--main/php_version.h8
-rw-r--r--main/rfc1867.c14
-rw-r--r--main/snprintf.c34
-rw-r--r--main/snprintf.h17
-rw-r--r--main/spprintf.c20
-rw-r--r--main/streams/glob_wrapper.c1
-rw-r--r--main/streams/memory.c7
-rw-r--r--main/streams/plain_wrapper.c12
-rw-r--r--main/streams/streams.c2
-rw-r--r--main/streams/transports.c3
-rw-r--r--main/streams/userspace.c4
-rw-r--r--main/streams/xp_socket.c59
28 files changed, 332 insertions, 150 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index 018ef23b38..2a064bce48 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -262,7 +262,7 @@ SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen)
SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
{
if ((SG(post_max_size) > 0) && (SG(request_info).content_length > SG(post_max_size))) {
- php_error_docref(NULL, E_WARNING, "POST Content-Length of %pd bytes exceeds the limit of %pd bytes",
+ php_error_docref(NULL, E_WARNING, "POST Content-Length of " ZEND_LONG_FMT " bytes exceeds the limit of " ZEND_LONG_FMT " bytes",
SG(request_info).content_length, SG(post_max_size));
return;
}
@@ -479,10 +479,9 @@ SAPI_API void sapi_activate(void)
/* Cookies */
SG(request_info).cookie_data = sapi_module.read_cookies();
-
- if (sapi_module.activate) {
- sapi_module.activate();
- }
+ }
+ if (sapi_module.activate) {
+ sapi_module.activate();
}
if (sapi_module.input_filter_init) {
sapi_module.input_filter_init();
diff --git a/main/SAPI.h b/main/SAPI.h
index 1da441c39a..f857d3ec94 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -31,7 +31,6 @@
#include "win32/php_stdint.h"
#endif
#include <sys/stat.h>
-#include "php.h"
#define SAPI_OPTION_NO_CHDIR 1
#define SAPI_POST_BLOCK_SIZE 0x4000
@@ -232,7 +231,7 @@ struct _sapi_module_struct {
zend_stat_t *(*get_stat)(void);
char *(*getenv)(char *name, size_t name_len);
- void (*sapi_error)(int type, const char *error_msg, ...);
+ void (*sapi_error)(int type, const char *error_msg, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers);
int (*send_headers)(sapi_headers_struct *sapi_headers);
@@ -242,15 +241,12 @@ struct _sapi_module_struct {
char *(*read_cookies)(void);
void (*register_server_variables)(zval *track_vars_array);
- void (*log_message)(char *message);
+ void (*log_message)(char *message, int syslog_type_int);
double (*get_request_time)(void);
void (*terminate_process)(void);
char *php_ini_path_override;
- void (*block_interruptions)(void);
- void (*unblock_interruptions)(void);
-
void (*default_post_reader)(void);
void (*treat_data)(int arg, char *str, zval *destArray);
char *executable_location;
@@ -275,7 +271,6 @@ struct _sapi_module_struct {
unsigned int (*input_filter_init)(void);
};
-
struct _sapi_post_entry {
char *content_type;
uint content_type_len;
@@ -308,7 +303,23 @@ SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter);
END_EXTERN_C()
-#define STANDARD_SAPI_MODULE_PROPERTIES
+#define STANDARD_SAPI_MODULE_PROPERTIES \
+ NULL, /* php_ini_path_override */ \
+ NULL, /* default_post_reader */ \
+ NULL, /* treat_data */ \
+ NULL, /* executable_location */ \
+ 0, /* php_ini_ignore */ \
+ 0, /* php_ini_ignore_cwd */ \
+ NULL, /* get_fd */ \
+ NULL, /* force_http_10 */ \
+ NULL, /* get_target_uid */ \
+ NULL, /* get_target_gid */ \
+ NULL, /* input_filter */ \
+ NULL, /* ini_defaults */ \
+ 0, /* phpinfo_as_text; */ \
+ NULL, /* ini_entries; */ \
+ NULL, /* additional_functions */ \
+ NULL /* input_filter_init */
#endif /* SAPI_H */
diff --git a/main/fastcgi.c b/main/fastcgi.c
index f5e476c6e7..1e8a8064d7 100644
--- a/main/fastcgi.c
+++ b/main/fastcgi.c
@@ -741,7 +741,7 @@ int fcgi_listen(const char *path, int backlog)
#else
int path_len = strlen(path);
- if (path_len >= sizeof(sa.sa_unix.sun_path)) {
+ if (path_len >= (int)sizeof(sa.sa_unix.sun_path)) {
fcgi_log(FCGI_ERROR, "Listening socket's path name is too long.\n");
return -1;
}
@@ -1088,11 +1088,14 @@ static int fcgi_read_request(fcgi_request *req)
req->id = (hdr.requestIdB1 << 8) + hdr.requestIdB0;
if (hdr.type == FCGI_BEGIN_REQUEST && len == sizeof(fcgi_begin_request)) {
+ fcgi_begin_request *b;
+
if (safe_read(req, buf, len+padding) != len+padding) {
return 0;
}
- req->keep = (((fcgi_begin_request*)buf)->flags & FCGI_KEEP_CONN);
+ b = (fcgi_begin_request*)buf;
+ req->keep = (b->flags & FCGI_KEEP_CONN);
#ifdef TCP_NODELAY
if (req->keep && req->tcp && !req->nodelay) {
# ifdef _WIN32
@@ -1105,7 +1108,7 @@ static int fcgi_read_request(fcgi_request *req)
req->nodelay = 1;
}
#endif
- switch ((((fcgi_begin_request*)buf)->roleB1 << 8) + ((fcgi_begin_request*)buf)->roleB0) {
+ switch ((b->roleB1 << 8) + b->roleB0) {
case FCGI_RESPONDER:
fcgi_hash_set(&req->env, FCGI_HASH_FUNC("FCGI_ROLE", sizeof("FCGI_ROLE")-1), "FCGI_ROLE", sizeof("FCGI_ROLE")-1, "RESPONDER", sizeof("RESPONDER")-1);
break;
@@ -1591,7 +1594,7 @@ int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int l
}
memcpy(req->out_pos, str, len);
req->out_pos += len;
- } else if (len - limit < sizeof(req->out_buf) - sizeof(fcgi_header)) {
+ } else if (len - limit < (int)(sizeof(req->out_buf) - sizeof(fcgi_header))) {
if (!req->out_hdr) {
open_packet(req, type);
}
diff --git a/main/fastcgi.h b/main/fastcgi.h
index 925d60c9bb..4cafc69c6e 100644
--- a/main/fastcgi.h
+++ b/main/fastcgi.h
@@ -31,7 +31,7 @@
*/
#define FCGI_HASH_FUNC(var, var_len) \
- (UNEXPECTED(var_len < 3) ? var_len : \
+ (UNEXPECTED(var_len < 3) ? (unsigned int)var_len : \
(((unsigned int)var[3]) << 2) + \
(((unsigned int)var[var_len-2]) << 4) + \
(((unsigned int)var[var_len-1]) << 2) + \
@@ -105,7 +105,7 @@ void fcgi_set_in_shutdown(int new_value);
void fcgi_request_set_keep(fcgi_request *req, int new_value);
#ifndef HAVE_ATTRIBUTE_WEAK
-typedef void (*fcgi_logger)(int type, const char *fmt, ...);
+typedef void (*fcgi_logger)(int type, const char *fmt, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
void fcgi_set_logger(fcgi_logger lg);
#endif
diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h
index adadb3fba8..b3c4d7f3ab 100644
--- a/main/fopen_wrappers.h
+++ b/main/fopen_wrappers.h
@@ -34,15 +34,8 @@ PHPAPI int php_check_open_basedir(const char *path);
PHPAPI int php_check_open_basedir_ex(const char *path, int warn);
PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path);
-/* {{{ OPENBASEDIR_CHECKPATH(filename) to ease merge between 6.x and 5.x */
-#if PHP_API_VERSION < 20100412
-# define OPENBASEDIR_CHECKPATH(filename) \
- (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(filename)
-#else
-#define OPENBASEDIR_CHECKPATH(filename) \
- php_check_open_basedir(filename)
-#endif
-/* }}} */
+/* OPENBASEDIR_CHECKPATH(filename) to ease merge between 6.x and 5.x */
+#define OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)
PHPAPI int php_check_safe_mode_include_dir(const char *path);
diff --git a/main/getopt.c b/main/getopt.c
index 003a13ad32..a875289d29 100644
--- a/main/getopt.c
+++ b/main/getopt.c
@@ -89,7 +89,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
}
if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
const char *pos;
- int arg_end = (int)strlen(argv[*optind])-1;
+ size_t arg_end = strlen(argv[*optind])-1;
/* '--' indicates end of args if not followed by a known long option name */
if (argv[*optind][2] == '\0') {
diff --git a/main/main.c b/main/main.c
index 4b145fcc70..863daec18a 100644
--- a/main/main.c
+++ b/main/main.c
@@ -131,7 +131,7 @@ static PHP_INI_MH(OnSetPrecision)
zend_long i;
ZEND_ATOL(i, ZSTR_VAL(new_value));
- if (i >= 0) {
+ if (i >= -1) {
EG(precision) = i;
return SUCCESS;
} else {
@@ -142,6 +142,23 @@ static PHP_INI_MH(OnSetPrecision)
/* {{{ PHP_INI_MH
*/
+static PHP_INI_MH(OnSetSerializePrecision)
+{
+ zend_long i;
+
+ ZEND_ATOL(i, ZSTR_VAL(new_value));
+ if (i >= -1) {
+ PG(serialize_precision) = i;
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
+}
+/* }}} */
+
+
+/* {{{ PHP_INI_MH
+ */
static PHP_INI_MH(OnChangeMemoryLimit)
{
if (new_value) {
@@ -386,10 +403,27 @@ static PHP_INI_DISP(display_errors_mode)
/* {{{ PHP_INI_MH
*/
+static PHP_INI_MH(OnUpdateDefaultCharset)
+{
+ if (new_value) {
+ OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+#ifdef PHP_WIN32
+ php_win32_cp_do_update(ZSTR_VAL(new_value));
+#endif
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ PHP_INI_MH
+ */
static PHP_INI_MH(OnUpdateInternalEncoding)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+#ifdef PHP_WIN32
+ php_win32_cp_do_update(ZSTR_VAL(new_value));
+#endif
}
return SUCCESS;
}
@@ -401,6 +435,9 @@ static PHP_INI_MH(OnUpdateInputEncoding)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+#ifdef PHP_WIN32
+ php_win32_cp_do_update(NULL);
+#endif
}
return SUCCESS;
}
@@ -412,6 +449,9 @@ static PHP_INI_MH(OnUpdateOutputEncoding)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+#ifdef PHP_WIN32
+ php_win32_cp_do_update(NULL);
+#endif
}
return SUCCESS;
}
@@ -516,14 +556,14 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("serialize_precision", "17", PHP_INI_ALL, OnUpdateLongGEZero, serialize_precision, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("serialize_precision", "-1", PHP_INI_ALL, OnSetSerializePrecision, serialize_precision, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct, sapi_globals)
+ STD_PHP_INI_ENTRY("default_charset", PHP_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateDefaultCharset, default_charset, sapi_globals_struct, sapi_globals)
STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct, sapi_globals)
STD_PHP_INI_ENTRY("internal_encoding", NULL, PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("input_encoding", NULL, PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, php_core_globals, core_globals)
@@ -572,7 +612,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
- STD_PHP_INI_BOOLEAN("exit_on_timeout", "0", PHP_INI_ALL, OnUpdateBool, exit_on_timeout, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("hard_timeout", "2", PHP_INI_SYSTEM, OnUpdateLong, hard_timeout, zend_executor_globals, executor_globals)
#ifdef PHP_WIN32
STD_PHP_INI_BOOLEAN("windows.show_crt_warning", "0", PHP_INI_ALL, OnUpdateBool, windows_show_crt_warning, php_core_globals, core_globals)
#endif
@@ -607,9 +647,9 @@ PHPAPI int php_get_module_initialized(void)
}
/* }}} */
-/* {{{ php_log_err
+/* {{{ php_log_err_with_severity
*/
-PHPAPI ZEND_COLD void php_log_err(char *log_message)
+PHPAPI ZEND_COLD void php_log_err_with_severity(char *log_message, int syslog_type_int)
{
int fd = -1;
time_t error_time;
@@ -624,7 +664,7 @@ PHPAPI ZEND_COLD void php_log_err(char *log_message)
if (PG(error_log) != NULL) {
#ifdef HAVE_SYSLOG_H
if (!strcmp(PG(error_log), "syslog")) {
- php_syslog(LOG_NOTICE, "%s", log_message);
+ php_syslog(syslog_type_int, "%s", log_message);
PG(in_error_log) = 0;
return;
}
@@ -664,7 +704,7 @@ PHPAPI ZEND_COLD void php_log_err(char *log_message)
/* Otherwise fall back to the default logging location, if we have one */
if (sapi_module.log_message) {
- sapi_module.log_message(log_message);
+ sapi_module.log_message(log_message, syslog_type_int);
}
PG(in_error_log) = 0;
}
@@ -1049,6 +1089,7 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u
if (display && (EG(error_reporting) & type || (type & E_CORE))
&& (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
char *error_type_str;
+ int syslog_type_int = LOG_NOTICE;
switch (type) {
case E_ERROR:
@@ -1056,29 +1097,36 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u
case E_COMPILE_ERROR:
case E_USER_ERROR:
error_type_str = "Fatal error";
+ syslog_type_int = LOG_ERR;
break;
case E_RECOVERABLE_ERROR:
- error_type_str = "Catchable fatal error";
+ error_type_str = "Recoverable fatal error";
+ syslog_type_int = LOG_ERR;
break;
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_WARNING:
error_type_str = "Warning";
+ syslog_type_int = LOG_WARNING;
break;
case E_PARSE:
error_type_str = "Parse error";
+ syslog_type_int = LOG_EMERG;
break;
case E_NOTICE:
case E_USER_NOTICE:
error_type_str = "Notice";
+ syslog_type_int = LOG_NOTICE;
break;
case E_STRICT:
error_type_str = "Strict Standards";
+ syslog_type_int = LOG_INFO;
break;
case E_DEPRECATED:
case E_USER_DEPRECATED:
error_type_str = "Deprecated";
+ syslog_type_int = LOG_INFO;
break;
default:
error_type_str = "Unknown error";
@@ -1093,13 +1141,13 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u
}
#endif
spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
- php_log_err(log_buffer);
+ php_log_err_with_severity(log_buffer, syslog_type_int);
efree(log_buffer);
}
if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) {
if (PG(xmlrpc_errors)) {
- php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%pd</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno);
+ 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 %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno);
} else {
char *prepend_string = INI_STR("error_prepend_string");
char *append_string = INI_STR("error_append_string");
@@ -1230,15 +1278,17 @@ PHPAPI char *php_get_current_user(void)
return "";
} else {
#ifdef PHP_WIN32
- char name[256];
- DWORD len = sizeof(name)-1;
+ char *name = php_win32_get_username();
+ int len;
- if (!GetUserName(name, &len)) {
+ if (!name) {
return "";
}
+ len = (int)strlen(name);
name[len] = '\0';
SG(request_info).current_user_length = len;
SG(request_info).current_user = estrndup(name, len);
+ free(name);
return SG(request_info).current_user;
#else
struct passwd *pwd;
@@ -1439,7 +1489,7 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void
if (message==ZMSG_MEMORY_LEAK_DETECTED) {
zend_leak_info *t = (zend_leak_info *) data;
- snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%zu bytes), script=%s\n", t->filename, t->lineno, (zend_uintptr_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
+ snprintf(memory_leak_buf, 512, "%s(%d) : Freeing " ZEND_ADDR_FMT " (%zu bytes), script=%s\n", t->filename, t->lineno, (size_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
if (t->orig_filename) {
char relay_buf[512];
@@ -1503,8 +1553,6 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void
void php_on_timeout(int seconds)
{
PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
- zend_set_timeout(EG(timeout_seconds), 1);
- if(PG(exit_on_timeout)) sapi_terminate_process();
}
#if PHP_SIGCHILD
@@ -1589,9 +1637,7 @@ int php_request_startup(void)
zend_activate();
sapi_activate();
-#ifdef ZEND_SIGNALS
zend_signal_activate();
-#endif
if (PG(max_input_time) == -1) {
zend_set_timeout(EG(timeout_seconds), 1);
@@ -2071,8 +2117,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
zuf.write_function = php_output_wrapper;
zuf.fopen_function = php_fopen_wrapper_for_zend;
zuf.message_handler = php_message_handler_for_zend;
- zuf.block_interruptions = sapi_module.block_interruptions;
- zuf.unblock_interruptions = sapi_module.unblock_interruptions;
zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
zuf.ticks_function = php_run_ticks;
zuf.on_timeout = php_on_timeout;
@@ -2138,6 +2182,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", ZEND_LONG_MAX, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MIN", ZEND_LONG_MIN, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", SIZEOF_ZEND_LONG, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("PHP_FD_SETSIZE", FD_SETSIZE, CONST_PERSISTENT | CONST_CS);
#ifdef PHP_WIN32
REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
diff --git a/main/network.c b/main/network.c
index 6b04a0701f..b983045fae 100644
--- a/main/network.c
+++ b/main/network.c
@@ -489,6 +489,11 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&sockoptval, sizeof(sockoptval));
}
#endif
+#ifdef TCP_NODELAY
+ if (sockopts & STREAM_SOCKOP_TCP_NODELAY) {
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&sockoptval, sizeof(sockoptval));
+ }
+#endif
n = bind(sock, sa, socklen);
@@ -728,7 +733,8 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock,
socklen_t *addrlen,
struct timeval *timeout,
zend_string **error_string,
- int *error_code
+ int *error_code,
+ int tcp_nodelay
)
{
php_socket_t clisock = -1;
@@ -752,6 +758,11 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock,
textaddr,
addr, addrlen
);
+ if (tcp_nodelay) {
+#ifdef TCP_NODELAY
+ setsockopt(clisock, IPPROTO_TCP, TCP_NODELAY, (char*)&tcp_nodelay, sizeof(tcp_nodelay));
+#endif
+ }
} else {
error = php_socket_errno();
}
@@ -769,7 +780,6 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock,
/* }}} */
-
/* Connect to a remote host using an interruptible connect with optional timeout.
* Optionally, the connect can be made asynchronously, which will implicitly
* enable non-blocking mode on the socket.
@@ -904,6 +914,15 @@ skip_bind:
}
}
#endif
+
+#ifdef TCP_NODELAY
+ {
+ int val = 1;
+ if (sockopts & STREAM_SOCKOP_TCP_NODELAY) {
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&val, sizeof(val));
+ }
+ }
+#endif
n = php_network_connect_socket(sock, sa, socklen, asynchronous,
timeout ? &working_timeout : NULL,
error_string, error_code);
diff --git a/main/php.h b/main/php.h
index 25fffee714..9b1c8b9b2b 100644
--- a/main/php.h
+++ b/main/php.h
@@ -26,7 +26,7 @@
#include <dmalloc.h>
#endif
-#define PHP_API_VERSION 20151012
+#define PHP_API_VERSION 20160303
#define PHP_HAVE_STREAMS
#define YYDEBUG 0
#define PHP_DEFAULT_CHARSET "UTF-8"
@@ -231,6 +231,14 @@ char *strerror(int);
#define INT_MIN (- INT_MAX - 1)
#endif
+/* double limits */
+#include <float.h>
+#if defined(DBL_MANT_DIG) && defined(DBL_MIN_EXP)
+#define PHP_DOUBLE_MAX_LENGTH (3 + DBL_MANT_DIG - DBL_MIN_EXP)
+#else
+#define PHP_DOUBLE_MAX_LENGTH 1080
+#endif
+
#define PHP_GCC_VERSION ZEND_GCC_VERSION
#define PHP_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_MALLOC
#define PHP_ATTRIBUTE_FORMAT ZEND_ATTRIBUTE_FORMAT
@@ -248,7 +256,10 @@ END_EXTERN_C()
#define STR_PRINT(str) ((str)?(str):"")
#ifndef MAXPATHLEN
-# ifdef PATH_MAX
+# ifdef PHP_WIN32
+# include "win32/ioutil.h"
+# define MAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
+# elif PATH_MAX
# define MAXPATHLEN PATH_MAX
# elif defined(MAX_PATH)
# define MAXPATHLEN MAX_PATH
@@ -280,7 +291,13 @@ PHPAPI size_t php_write(void *buf, size_t size);
PHPAPI size_t php_printf(const char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1,
2);
PHPAPI int php_get_module_initialized(void);
-PHPAPI ZEND_COLD void php_log_err(char *log_message);
+#ifdef HAVE_SYSLOG_H
+#include "php_syslog.h"
+#define php_log_err(msg) php_log_err_with_severity(msg, LOG_NOTICE)
+#else
+#define php_log_err(msg) php_log_err_with_severity(msg, 5)
+#endif
+PHPAPI ZEND_COLD void php_log_err_with_severity(char *log_message, int syslog_type_int);
int Debug(char *format, ...) PHP_ATTRIBUTE_FORMAT(printf, 1, 2);
int cfgparse(void);
END_EXTERN_C()
@@ -324,7 +341,7 @@ END_EXTERN_C()
BEGIN_EXTERN_C()
PHPAPI extern int (*php_register_internal_extensions_func)(void);
PHPAPI int php_register_internal_extensions(void);
-PHPAPI int php_mergesort(void *base, size_t nmemb, register size_t size, int (*cmp)(const void *, const void *));
+PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *, const void *));
PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
PHPAPI void php_com_initialize(void);
PHPAPI char *php_get_current_user(void);
diff --git a/main/php_globals.h b/main/php_globals.h
index d77c3ed46b..b067805e14 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -147,7 +147,6 @@ struct _php_core_globals {
char *disable_functions;
char *disable_classes;
zend_bool allow_url_include;
- zend_bool exit_on_timeout;
#ifdef PHP_WIN32
zend_bool com_initialized;
#endif
diff --git a/main/php_ini.c b/main/php_ini.c
index cf9711fd67..75b1695ec4 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -640,7 +640,7 @@ int php_init_config(void)
}
if (!debpath[0]) {
/* empty string means default builtin value
- to allow "/foo/phd.d:" or ":/foo/php.d" */
+ to allow "/foo/php.d:" or ":/foo/php.d" */
debpath = PHP_CONFIG_FILE_SCAN_DIR;
}
lenpath = (int)strlen(debpath);
diff --git a/main/php_network.h b/main/php_network.h
index 28a9ffd1b0..5385fe13d4 100644
--- a/main/php_network.h
+++ b/main/php_network.h
@@ -28,6 +28,7 @@
#else
# undef closesocket
# define closesocket close
+# include <netinet/tcp.h>
#endif
#ifndef HAVE_SHUTDOWN
@@ -115,6 +116,7 @@ typedef int php_socket_t;
#define STREAM_SOCKOP_SO_BROADCAST (1 << 2)
#define STREAM_SOCKOP_IPV6_V6ONLY (1 << 3)
#define STREAM_SOCKOP_IPV6_V6ONLY_ENABLED (1 << 4)
+#define STREAM_SOCKOP_TCP_NODELAY (1 << 5)
/* uncomment this to debug poll(2) emulation on systems that have poll(2) */
@@ -269,7 +271,8 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock,
socklen_t *addrlen,
struct timeval *timeout,
zend_string **error_string,
- int *error_code
+ int *error_code,
+ int tcp_nodelay
);
PHPAPI int php_network_get_sock_name(php_socket_t sock,
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index be69af3d0f..9426297133 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -19,6 +19,7 @@
/* $Id$ */
#include "php.h"
+#include "php_open_temporary_file.h"
#include <errno.h>
#include <sys/types.h>
@@ -97,7 +98,13 @@
static int php_do_open_temporary_file(const char *path, const char *pfx, zend_string **opened_path_p)
{
char *trailing_slash;
+#ifdef PHP_WIN32
+ char *opened_path = NULL;
+ size_t opened_path_len;
+ wchar_t *cwdw, *pfxw, pathw[MAXPATHLEN];
+#else
char opened_path[MAXPATHLEN];
+#endif
char cwd[MAXPATHLEN];
cwd_state new_state;
int fd = -1;
@@ -138,23 +145,47 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
trailing_slash = "/";
}
+#ifndef PHP_WIN32
if (snprintf(opened_path, MAXPATHLEN, "%s%s%sXXXXXX", new_state.cwd, trailing_slash, pfx) >= MAXPATHLEN) {
efree(new_state.cwd);
return -1;
}
+#endif
#ifdef PHP_WIN32
+ cwdw = php_win32_ioutil_any_to_w(new_state.cwd);
+ pfxw = php_win32_ioutil_any_to_w(pfx);
+ if (!cwdw || !pfxw) {
+ free(cwdw);
+ free(pfxw);
+ efree(new_state.cwd);
+ return -1;
+ }
+
+ if (GetTempFileNameW(cwdw, pfxw, 0, pathw)) {
+ opened_path = php_win32_ioutil_conv_w_to_any(pathw, PHP_WIN32_CP_IGNORE_LEN, &opened_path_len);
+ if (!opened_path || opened_path_len >= MAXPATHLEN) {
+ free(cwdw);
+ free(pfxw);
+ efree(new_state.cwd);
+ return -1;
+ }
+ assert(strlen(opened_path) == opened_path_len);
- if (GetTempFileName(new_state.cwd, pfx, 0, opened_path)) {
/* Some versions of windows set the temp file to be read-only,
* which means that opening it will fail... */
if (VCWD_CHMOD(opened_path, 0600)) {
+ free(cwdw);
+ free(pfxw);
efree(new_state.cwd);
+ free(opened_path);
return -1;
}
fd = VCWD_OPEN_MODE(opened_path, open_flags, 0600);
}
+ free(cwdw);
+ free(pfxw);
#elif defined(HAVE_MKSTEMP)
fd = mkstemp(opened_path);
#else
@@ -163,9 +194,16 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
}
#endif
+#ifdef PHP_WIN32
+ if (fd != -1 && opened_path_p) {
+ *opened_path_p = zend_string_init(opened_path, opened_path_len, 0);
+ }
+ free(opened_path);
+#else
if (fd != -1 && opened_path_p) {
*opened_path_p = zend_string_init(opened_path, strlen(opened_path), 0);
}
+#endif
efree(new_state.cwd);
return fd;
}
@@ -203,14 +241,18 @@ PHPAPI const char* php_get_temporary_directory(void)
* the environment values TMP and TEMP (in order) first.
*/
{
- char sTemp[MAX_PATH];
- DWORD len = GetTempPath(sizeof(sTemp),sTemp);
+ wchar_t sTemp[MAXPATHLEN];
+ char *tmp;
+ size_t len = GetTempPathW(MAXPATHLEN, sTemp);
assert(0 < len); /* should *never* fail! */
- if (sTemp[len - 1] == DEFAULT_SLASH) {
- PG(php_sys_temp_dir) = estrndup(sTemp, len - 1);
- } else {
- PG(php_sys_temp_dir) = estrndup(sTemp, len);
+
+ if (NULL == (tmp = php_win32_ioutil_conv_w_to_any(sTemp, len, &len))) {
+ return NULL;
}
+
+ PG(php_sys_temp_dir) = estrndup(tmp, len - 1);
+
+ free(tmp);
return PG(php_sys_temp_dir);
}
#else
@@ -249,7 +291,7 @@ PHPAPI const char* php_get_temporary_directory(void)
* This function should do its best to return a file pointer to a newly created
* unique file, on every platform.
*/
-PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, zend_bool open_basedir_check)
+PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, uint32_t flags)
{
int fd;
const char *temp_dir;
@@ -265,7 +307,7 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin
def_tmp:
temp_dir = php_get_temporary_directory();
- if (temp_dir && *temp_dir != '\0' && (!open_basedir_check || !php_check_open_basedir(temp_dir))) {
+ if (temp_dir && *temp_dir != '\0' && (!(flags & PHP_TMP_FILE_OPEN_BASEDIR_CHECK) || !php_check_open_basedir(temp_dir))) {
return php_do_open_temporary_file(temp_dir, pfx, opened_path_p);
} else {
return -1;
@@ -276,6 +318,9 @@ def_tmp:
fd = php_do_open_temporary_file(dir, pfx, opened_path_p);
if (fd == -1) {
/* Use default temporary directory. */
+ if (!(flags & PHP_TMP_FILE_SILENT)) {
+ php_error_docref(NULL, E_NOTICE, "file created in the system's temporary directory");
+ }
goto def_tmp;
}
return fd;
diff --git a/main/php_open_temporary_file.h b/main/php_open_temporary_file.h
index ae58a8508e..0a9b257150 100644
--- a/main/php_open_temporary_file.h
+++ b/main/php_open_temporary_file.h
@@ -21,9 +21,12 @@
#ifndef PHP_OPEN_TEMPORARY_FILE_H
#define PHP_OPEN_TEMPORARY_FILE_H
+#define PHP_TMP_FILE_OPEN_BASEDIR_CHECK (1<<0)
+#define PHP_TMP_FILE_SILENT (1<<1)
+
BEGIN_EXTERN_C()
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, zend_string **opened_path_p);
-PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, zend_bool open_basedir_check);
+PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, uint32_t flags);
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, zend_string **opened_path_p);
PHPAPI const char *php_get_temporary_directory(void);
END_EXTERN_C()
diff --git a/main/php_output.h b/main/php_output.h
index 9b6e568584..03bd6cca1d 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -159,8 +159,8 @@ PHPAPI ZEND_EXTERN_MODULE_GLOBALS(output)
#define PHPWRITE(str, str_len) php_output_write((str), (str_len))
#define PHPWRITE_H(str, str_len) php_output_write_unbuffered((str), (str_len))
-#define PUTC(c) (php_output_write((const char *) &(c), 1), (c))
-#define PUTC_H(c) (php_output_write_unbuffered((const char *) &(c), 1), (c))
+#define PUTC(c) php_output_write((const char *) &(c), 1)
+#define PUTC_H(c) php_output_write_unbuffered((const char *) &(c), 1)
#define PUTS(str) do { \
const char *__str = (str); \
diff --git a/main/php_variables.c b/main/php_variables.c
index d3cfb7f737..69fe2c24f6 100644
--- a/main/php_variables.c
+++ b/main/php_variables.c
@@ -79,7 +79,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
/* ignore leading spaces in the variable name */
- while (*var_name && *var_name==' ') {
+ while (*var_name==' ') {
var_name++;
}
@@ -109,6 +109,26 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
return;
}
+ if (var_len == sizeof("this")-1 && EG(current_execute_data)) {
+ zend_execute_data *ex = EG(current_execute_data);
+
+ while (ex) {
+ if (ex->func && ZEND_USER_CODE(ex->func->common.type)) {
+ if ((ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE)
+ && ex->symbol_table == symtable1) {
+ if (memcmp(var, "this", sizeof("this")-1) == 0) {
+ zend_throw_error(NULL, "Cannot re-assign $this");
+ zval_dtor(val);
+ free_alloca(var_orig, use_heap);
+ return;
+ }
+ }
+ break;
+ }
+ ex = ex->prev_execute_data;
+ }
+ }
+
/* GLOBALS hijack attempt, reject parameter */
if (symtable1 == &EG(symbol_table) &&
var_len == sizeof("GLOBALS")-1 &&
diff --git a/main/php_version.h b/main/php_version.h
index 9d36dcc091..252097d549 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 */
#define PHP_MAJOR_VERSION 7
-#define PHP_MINOR_VERSION 0
-#define PHP_RELEASE_VERSION 23
+#define PHP_MINOR_VERSION 1
+#define PHP_RELEASE_VERSION 9
#define PHP_EXTRA_VERSION "-dev"
-#define PHP_VERSION "7.0.23-dev"
-#define PHP_VERSION_ID 70023
+#define PHP_VERSION "7.1.9-dev"
+#define PHP_VERSION_ID 70109
diff --git a/main/rfc1867.c b/main/rfc1867.c
index 5949802d6d..264b234aa3 100644
--- a/main/rfc1867.c
+++ b/main/rfc1867.c
@@ -40,7 +40,9 @@
# define HAVE_ATOLL 1
#endif
-#define DEBUG_FILE_UPLOAD ZEND_DEBUG
+#ifndef DEBUG_FILE_UPLOAD
+# define DEBUG_FILE_UPLOAD 0
+#endif
static int dummy_encoding_translation(void)
{
@@ -620,7 +622,7 @@ static int multipart_buffer_read(multipart_buffer *self, char *buf, size_t bytes
char *bound;
/* fill buffer if needed */
- if (bytes > self->bytes_in_buffer) {
+ if (bytes > (size_t)self->bytes_in_buffer) {
fill_buffer(self);
}
@@ -1048,7 +1050,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
cancel_upload = UPLOAD_ERROR_A;
} else if (max_file_size && ((zend_long)(total_bytes+blen) > max_file_size)) {
#if DEBUG_FILE_UPLOAD
- sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of " ZEND_LONG_FMT " bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename);
+ sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of %" PRId64 " bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename);
#endif
cancel_upload = UPLOAD_ERROR_B;
} else if (blen > 0) {
@@ -1058,7 +1060,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
wlen = write(fd, buff, blen);
#endif
- if (wlen == -1) {
+ if (wlen == (size_t)-1) {
/* write failed */
#if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, "write() failed - %s", strerror(errno));
@@ -1066,7 +1068,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
cancel_upload = UPLOAD_ERROR_F;
} else if (wlen < blen) {
#if DEBUG_FILE_UPLOAD
- sapi_module.sapi_error(E_NOTICE, "Only %d bytes were written, expected to write %d", wlen, blen);
+ sapi_module.sapi_error(E_NOTICE, "Only %zd bytes were written, expected to write %zd", wlen, blen);
#endif
cancel_upload = UPLOAD_ERROR_F;
} else {
@@ -1257,7 +1259,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
}
#else
{
- int __len = snprintf(file_size_buf, 65, "%lld", total_bytes);
+ int __len = snprintf(file_size_buf, 65, "%" PRId64, total_bytes);
file_size_buf[__len] = '\0';
}
#endif
diff --git a/main/snprintf.c b/main/snprintf.c
index d96bb487b9..a6788c7f79 100644
--- a/main/snprintf.c
+++ b/main/snprintf.c
@@ -143,8 +143,12 @@ PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, c
{
char *digits, *dst, *src;
int i, decpt, sign;
+ int mode = ndigit >= 0 ? 2 : 0;
- digits = zend_dtoa(value, 2, ndigit, &decpt, &sign, NULL);
+ if (mode == 0) {
+ ndigit = 17;
+ }
+ digits = zend_dtoa(value, mode, ndigit, &decpt, &sign, NULL);
if (decpt == 9999) {
/*
* Infinity or NaN, convert to inf or nan with sign.
@@ -555,11 +559,11 @@ typedef struct buf_area buffy;
* to be printed.
*/
#define FIX_PRECISION( adjust, precision, s, s_len ) \
- if ( adjust ) \
- while ( s_len < precision ) \
- { \
- *--s = '0' ; \
- s_len++ ; \
+ if ( adjust ) \
+ while ( s_len < (size_t)precision ) \
+ { \
+ *--s = '0' ; \
+ s_len++ ; \
}
/*
@@ -796,14 +800,14 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
*/
switch (*fmt) {
case 'Z': {
- zvp = (zval*) va_arg(ap, zval*);
+ zvp = (zval*) va_arg(ap, zval*);
free_zcopy = zend_make_printable_zval(zvp, &zcopy);
if (free_zcopy) {
zvp = &zcopy;
}
s_len = Z_STRLEN_P(zvp);
s = Z_STRVAL_P(zvp);
- if (adjust_precision && precision < s_len) {
+ if (adjust_precision && (size_t)precision < s_len) {
s_len = precision;
}
break;
@@ -991,7 +995,7 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
s = va_arg(ap, char *);
if (s != NULL) {
s_len = strlen(s);
- if (adjust_precision && precision < s_len) {
+ if (adjust_precision && (size_t)precision < s_len) {
s_len = precision;
}
} else {
@@ -1190,14 +1194,14 @@ fmt_error:
*--s = prefix_char;
s_len++;
}
- if (adjust_width && adjust == RIGHT && min_width > s_len) {
+ if (adjust_width && adjust == RIGHT && (size_t)min_width > s_len) {
if (pad_char == '0' && prefix_char != NUL) {
INS_CHAR(*s, sp, bep, cc)
s++;
s_len--;
min_width--;
}
- PAD(min_width, s_len, pad_char);
+ PAD((size_t)min_width, s_len, pad_char);
}
/*
* Print the string s.
@@ -1207,8 +1211,8 @@ fmt_error:
s++;
}
- if (adjust_width && adjust == LEFT && min_width > s_len)
- PAD(min_width, s_len, pad_char);
+ if (adjust_width && adjust == LEFT && (size_t)min_width > s_len)
+ PAD((size_t)min_width, s_len, pad_char);
if (free_zcopy) {
zval_dtor(&zcopy);
}
@@ -1263,7 +1267,7 @@ PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...) /* {{{
va_start(ap, format);
strx_printv(&cc, buf, len, format, ap);
va_end(ap);
- if (cc >= len) {
+ if ((size_t)cc >= len) {
cc = (int)len -1;
buf[cc] = '\0';
}
@@ -1276,7 +1280,7 @@ PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list a
int cc;
strx_printv(&cc, buf, len, format, ap);
- if (cc >= len) {
+ if ((size_t)cc >= len) {
cc = (int)len -1;
buf[cc] = '\0';
}
diff --git a/main/snprintf.h b/main/snprintf.h
index 3585a37a2d..7abf55643e 100644
--- a/main/snprintf.h
+++ b/main/snprintf.h
@@ -78,15 +78,16 @@ typedef enum {
BEGIN_EXTERN_C()
-PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...);
+PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);
PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list ap);
-PHPAPI int ap_php_snprintf(char *, size_t, const char *, ...);
+PHPAPI int ap_php_snprintf(char *, size_t, const char *, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4);
PHPAPI int ap_php_vsnprintf(char *, size_t, const char *, va_list ap);
PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap);
-PHPAPI int ap_php_asprintf(char **buf, const char *format, ...);
+PHPAPI int ap_php_asprintf(char **buf, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
PHPAPI int php_sprintf (char* s, const char* format, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
PHPAPI char * php_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf);
-PHPAPI char * php_conv_fp(register char format, register double num,
+PHPAPI char * php_0cvt(double value, int ndigit, char dec_point, char exponent, char *buf);
+PHPAPI char * php_conv_fp(char format, double num,
boolean_e add_dp, int precision, char dec_point, bool_int * is_negative, char *buf, size_t *len);
END_EXTERN_C()
@@ -153,11 +154,11 @@ typedef enum {
typedef WIDE_INT wide_int;
typedef unsigned WIDE_INT u_wide_int;
-PHPAPI char * ap_php_conv_10(register wide_int num, register bool_int is_unsigned,
- register bool_int * is_negative, char *buf_end, register size_t *len);
+PHPAPI char * ap_php_conv_10(wide_int num, bool_int is_unsigned,
+ bool_int * is_negative, char *buf_end, size_t *len);
-PHPAPI char * ap_php_conv_p2(register u_wide_int num, register int nbits,
- char format, char *buf_end, register size_t *len);
+PHPAPI char * ap_php_conv_p2(u_wide_int num, int nbits,
+ char format, char *buf_end, size_t *len);
/* The maximum precision that's allowed for float conversion. Does not include
* decimal separator, exponent, sign, terminator. Currently does not affect
diff --git a/main/spprintf.c b/main/spprintf.c
index 6c33e19c33..c8ec27dfcc 100644
--- a/main/spprintf.c
+++ b/main/spprintf.c
@@ -152,13 +152,9 @@
/*
* NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
- *
- * XXX: this is a magic number; do not decrease it
- * Emax = 1023
- * NDIG = 320
- * NUM_BUF_SIZE >= strlen("-") + Emax + strlrn(".") + NDIG + strlen("E+1023") + 1;
+ * which can be at most max length of double
*/
-#define NUM_BUF_SIZE 2048
+#define NUM_BUF_SIZE PHP_DOUBLE_MAX_LENGTH
#define NUM(c) (c - '0')
@@ -182,7 +178,7 @@
*/
#define FIX_PRECISION(adjust, precision, s, s_len) do { \
if (adjust) \
- while (s_len < precision) { \
+ while (s_len < (size_t)precision) { \
*--s = '0'; \
s_len++; \
} \
@@ -306,8 +302,8 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt
} else if (*fmt == '*') {
precision = va_arg(ap, int);
fmt++;
- if (precision < 0)
- precision = 0;
+ if (precision < -1)
+ precision = -1;
} else
precision = 0;
@@ -417,7 +413,7 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt
}
s_len = Z_STRLEN_P(zvp);
s = Z_STRVAL_P(zvp);
- if (adjust_precision && precision < s_len) {
+ if (adjust_precision && (size_t)precision < s_len) {
s_len = precision;
}
break;
@@ -803,7 +799,7 @@ fmt_error:
*--s = prefix_char;
s_len++;
}
- if (adjust_width && adjust == RIGHT && min_width > s_len) {
+ if (adjust_width && adjust == RIGHT && (size_t)min_width > s_len) {
if (pad_char == '0' && prefix_char != NUL) {
INS_CHAR(xbuf, *s, is_char);
s++;
@@ -817,7 +813,7 @@ fmt_error:
*/
INS_STRING(xbuf, s, s_len, is_char);
- if (adjust_width && adjust == LEFT && min_width > s_len) {
+ if (adjust_width && adjust == LEFT && (size_t)min_width > s_len) {
PAD_CHAR(xbuf, pad_char, min_width - s_len, is_char);
}
diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c
index f41ce19d23..1288fa6bad 100644
--- a/main/streams/glob_wrapper.c
+++ b/main/streams/glob_wrapper.c
@@ -271,6 +271,7 @@ static php_stream_wrapper_ops php_glob_stream_wrapper_ops = {
NULL,
NULL,
NULL,
+ NULL,
NULL
};
diff --git a/main/streams/memory.c b/main/streams/memory.c
index f4fd6a8f02..39578dcffa 100644
--- a/main/streams/memory.c
+++ b/main/streams/memory.c
@@ -700,7 +700,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
}
/* found parameter ... the heart of cs ppl lies in +1/-1 or was it +2 this time? */
plen = sep - path;
- vlen = (semi ? semi - sep : mlen - plen) - 1 /* '=' */;
+ vlen = (semi ? (size_t)(semi - sep) : (mlen - plen)) - 1 /* '=' */;
key = estrndup(path, plen);
if (plen != sizeof("mediatype")-1 || memcmp(key, "mediatype", sizeof("mediatype")-1)) {
add_assoc_stringl_ex(&meta, key, plen, sep + 1, vlen);
@@ -725,7 +725,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
dlen--;
if (base64) {
- base64_comma = php_base64_decode((const unsigned char *)comma, dlen);
+ base64_comma = php_base64_decode_ex((const unsigned char *)comma, dlen, 1);
if (!base64_comma) {
zval_ptr_dtor(&meta);
php_stream_wrapper_log_error(wrapper, options, "rfc2397: unable to decode");
@@ -775,7 +775,8 @@ PHPAPI php_stream_wrapper_ops php_stream_rfc2397_wops = {
NULL, /* unlink */
NULL, /* rename */
NULL, /* mkdir */
- NULL /* rmdir */
+ NULL, /* rmdir */
+ NULL, /* stream_metadata */
};
PHPAPI php_stream_wrapper php_stream_rfc2397_wrapper = {
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 9643617aef..25eacceec5 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -42,6 +42,8 @@
#ifdef PHP_WIN32
# include "win32/winutil.h"
# include "win32/time.h"
+# include "win32/ioutil.h"
+# include "win32/readdir.h"
#endif
#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC)
@@ -471,7 +473,11 @@ static int php_stdiop_close(php_stream *stream, int close_handle)
return 0; /* everything should be closed already -> success */
}
if (data->temp_name) {
+#ifdef PHP_WIN32
+ php_win32_ioutil_unlink(ZSTR_VAL(data->temp_name));
+#else
unlink(ZSTR_VAL(data->temp_name));
+#endif
/* temporary streams are never persistent */
zend_string_release(data->temp_name);
data->temp_name = NULL;
@@ -1005,9 +1011,11 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
return ret;
}
}
-
+#ifdef PHP_WIN32
+ fd = php_win32_ioutil_open(realpath, open_flags, 0666);
+#else
fd = open(realpath, open_flags, 0666);
-
+#endif
if (fd != -1) {
if (options & STREAM_OPEN_FOR_INCLUDE) {
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 704ab71688..93ac083559 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1753,7 +1753,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
php_stream_wrapper *wrapper = NULL;
const char *p, *protocol = NULL;
- int n = 0;
+ size_t n = 0;
if (path_for_open) {
*path_for_open = (char*)path;
diff --git a/main/streams/transports.c b/main/streams/transports.c
index 6cf484e6e7..eb1909f1ce 100644
--- a/main/streams/transports.c
+++ b/main/streams/transports.c
@@ -60,7 +60,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
php_stream *stream = NULL;
php_stream_transport_factory factory = NULL;
const char *p, *protocol = NULL;
- int n = 0, failed = 0;
+ size_t n = 0;
+ int failed = 0;
zend_string *error_text = NULL;
struct timeval default_timeout = { 0, 0 };
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index e2cccf32d6..c6e4358dc1 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -304,9 +304,7 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
zval retval;
fci.size = sizeof(fci);
- fci.function_table = &uwrap->ce->function_table;
ZVAL_UNDEF(&fci.function_name);
- fci.symbol_table = NULL;
fci.object = Z_OBJ_P(object);
fci.retval = &retval;
fci.param_count = 0;
@@ -315,7 +313,7 @@ static void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php
fcc.initialized = 1;
fcc.function_handler = uwrap->ce->constructor;
- fcc.calling_scope = EG(scope);
+ fcc.calling_scope = zend_get_executed_scope();
fcc.called_scope = Z_OBJCE_P(object);
fcc.object = Z_OBJ_P(object);
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index 701a993ccc..e496a2d7fd 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -102,7 +102,7 @@ retry:
} while (err == EINTR);
}
estr = php_socket_strerror(err, NULL, 0);
- php_error_docref(NULL, E_NOTICE, "send of " ZEND_LONG_FMT " bytes failed with errno=%ld %s",
+ php_error_docref(NULL, E_NOTICE, "send of " ZEND_LONG_FMT " bytes failed with errno=%d %s",
(zend_long)count, err, estr);
efree(estr);
}
@@ -752,6 +752,18 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
}
#endif
+ if (stream->ops != &php_stream_udp_socket_ops /* TCP_NODELAY is only applicable for TCP */
+#ifdef AF_UNIX
+ && stream->ops != &php_stream_unix_socket_ops
+ && stream->ops != &php_stream_unixdg_socket_ops
+#endif
+ && PHP_STREAM_CONTEXT(stream)
+ && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "tcp_nodelay")) != NULL
+ && zend_is_true(tmpzval)
+ ) {
+ sockopts |= STREAM_SOCKOP_TCP_NODELAY;
+ }
+
/* Note: the test here for php_stream_udp_socket_ops is important, because we
* want the default to be TCP sockets so that the openssl extension can
* re-use this code. */
@@ -793,36 +805,37 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t
php_stream_xport_param *xparam STREAMS_DC)
{
int clisock;
+ zend_bool nodelay = 0;
+ zval *tmpzval = NULL;
xparam->outputs.client = NULL;
+ if ((NULL != PHP_STREAM_CONTEXT(stream)) &&
+ (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "tcp_nodelay")) != NULL &&
+ zend_is_true(tmpzval)) {
+ nodelay = 1;
+ }
+
clisock = php_network_accept_incoming(sock->socket,
- xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
- xparam->want_addr ? &xparam->outputs.addr : NULL,
- xparam->want_addr ? &xparam->outputs.addrlen : NULL,
- xparam->inputs.timeout,
- xparam->want_errortext ? &xparam->outputs.error_text : NULL,
- &xparam->outputs.error_code
- );
+ xparam->want_textaddr ? &xparam->outputs.textaddr : NULL,
+ xparam->want_addr ? &xparam->outputs.addr : NULL,
+ xparam->want_addr ? &xparam->outputs.addrlen : NULL,
+ xparam->inputs.timeout,
+ xparam->want_errortext ? &xparam->outputs.error_text : NULL,
+ &xparam->outputs.error_code,
+ nodelay);
if (clisock >= 0) {
- php_netstream_data_t *clisockdata;
+ php_netstream_data_t *clisockdata = (php_netstream_data_t*) emalloc(sizeof(*clisockdata));
- clisockdata = emalloc(sizeof(*clisockdata));
+ memcpy(clisockdata, sock, sizeof(*clisockdata));
+ clisockdata->socket = clisock;
- if (clisockdata == NULL) {
- close(clisock);
- /* technically a fatal error */
- } else {
- memcpy(clisockdata, sock, sizeof(*clisockdata));
- clisockdata->socket = clisock;
-
- xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
- if (xparam->outputs.client) {
- xparam->outputs.client->ctx = stream->ctx;
- if (stream->ctx) {
- GC_REFCOUNT(stream->ctx)++;
- }
+ xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
+ if (xparam->outputs.client) {
+ xparam->outputs.client->ctx = stream->ctx;
+ if (stream->ctx) {
+ GC_REFCOUNT(stream->ctx)++;
}
}
}