diff options
| author | Ondřej Surý <ondrej@sury.org> | 2011-02-16 10:13:02 +0100 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2011-02-16 10:13:02 +0100 |
| commit | fd5a0b31640419ca63d1ddeaffd6d3cf2a741814 (patch) | |
| tree | bfd17d84c5181d7b98d7d66f56573f4fc897e31c /main | |
| parent | 01fcdff3849c3691d9aaeaab735846ab6d8895ca (diff) | |
| download | php-upstream/5.3.5.tar.gz | |
Imported Upstream version 5.3.5upstream/5.3.5
Diffstat (limited to 'main')
| -rw-r--r-- | main/SAPI.c | 6 | ||||
| -rw-r--r-- | main/fopen_wrappers.c | 56 | ||||
| -rw-r--r-- | main/main.c | 11 | ||||
| -rw-r--r-- | main/network.c | 82 | ||||
| -rw-r--r-- | main/output.c | 282 | ||||
| -rw-r--r-- | main/php_config.h.in | 19 | ||||
| -rw-r--r-- | main/php_ini.c | 37 | ||||
| -rwxr-xr-x | main/php_streams.h | 10 | ||||
| -rw-r--r-- | main/php_version.h | 6 | ||||
| -rw-r--r-- | main/rfc1867.c | 47 | ||||
| -rw-r--r-- | main/streams/cast.c | 52 | ||||
| -rwxr-xr-x | main/streams/glob_wrapper.c | 4 | ||||
| -rw-r--r-- | main/streams/php_streams_int.h | 9 | ||||
| -rw-r--r-- | main/streams/plain_wrapper.c | 23 | ||||
| -rwxr-xr-x | main/streams/streams.c | 23 | ||||
| -rw-r--r-- | main/win95nt.h | 6 |
16 files changed, 406 insertions, 267 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index 1fd6ffd55..1681a4115 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: SAPI.c 296362 2010-03-18 22:37:25Z andrei $ */ +/* $Id: SAPI.c 305481 2010-11-18 04:09:02Z cataphract $ */ #include <ctype.h> #include <sys/stat.h> @@ -194,7 +194,7 @@ SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) int read_bytes; int allocated_bytes=SAPI_POST_BLOCK_SIZE+1; - if (SG(request_info).content_length > SG(post_max_size)) { + if ((SG(post_max_size) > 0) && (SG(request_info).content_length > SG(post_max_size))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size)); return; @@ -207,7 +207,7 @@ SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data) break; } SG(read_post_bytes) += read_bytes; - if (SG(read_post_bytes) > SG(post_max_size)) { + if ((SG(post_max_size) > 0) && (SG(read_post_bytes) > SG(post_max_size))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Actual POST length does not match Content-Length, and exceeds %ld bytes", SG(post_max_size)); break; } diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 015be9703..d171ea9a3 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fopen_wrappers.c 298277 2010-04-21 22:22:31Z felipe $ */ +/* $Id: fopen_wrappers.c 305698 2010-11-23 22:14:54Z pajoye $ */ /* {{{ includes */ @@ -173,21 +173,27 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path memcpy(path_tmp, resolved_name, path_len + 1); /* safe */ while (VCWD_REALPATH(path_tmp, resolved_name) == NULL) { -#ifdef HAVE_SYMLINK - if (nesting_level == 0) { - int ret; - char buf[MAXPATHLEN]; - - ret = readlink(path_tmp, buf, MAXPATHLEN - 1); - if (ret < 0) { - /* not a broken symlink, move along.. */ - } else { - /* put the real path into the path buffer */ - memcpy(path_tmp, buf, ret); - path_tmp[ret] = '\0'; +#if defined(PHP_WIN32) || defined(HAVE_SYMLINK) +#if defined(PHP_WIN32) + if (EG(windows_version_info).dwMajorVersion > 5) { +#endif + if (nesting_level == 0) { + int ret; + char buf[MAXPATHLEN]; + + ret = php_sys_readlink(path_tmp, buf, MAXPATHLEN - 1); + if (ret < 0) { + /* not a broken symlink, move along.. */ + } else { + /* put the real path into the path buffer */ + memcpy(path_tmp, buf, ret); + path_tmp[ret] = '\0'; + } } +#if defined(PHP_WIN32) } #endif +#endif #if defined(PHP_WIN32) || defined(NETWARE) path_file = strrchr(path_tmp, DEFAULT_SLASH); @@ -228,6 +234,9 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path resolved_basedir[resolved_basedir_len] = PHP_DIR_SEPARATOR; resolved_basedir[++resolved_basedir_len] = '\0'; } + } else { + resolved_basedir[resolved_basedir_len++] = PHP_DIR_SEPARATOR; + resolved_basedir[resolved_basedir_len] = '\0'; } resolved_name_len = strlen(resolved_name); @@ -244,8 +253,13 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path #else if (strncmp(resolved_basedir, resolved_name, resolved_basedir_len) == 0) { #endif - /* File is in the right directory */ - return 0; + if (resolved_name_len > resolved_basedir_len && + resolved_name[resolved_basedir_len - 1] != PHP_DIR_SEPARATOR) { + return -1; + } else { + /* File is in the right directory */ + return 0; + } } 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) { @@ -281,6 +295,14 @@ PHPAPI int php_check_open_basedir_ex(const char *path, int warn TSRMLS_DC) char *ptr; char *end; + /* Check if the path is too long so we can give a more useful error + * message. */ + if (strlen(path) > (MAXPATHLEN - 1)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "File name is longer than the maximum allowed path length on this platform (%d): %s", MAXPATHLEN, path); + errno = EINVAL; + return -1; + } + pathbuf = estrdup(PG(open_basedir)); ptr = pathbuf; @@ -519,6 +541,10 @@ PHPAPI char *php_resolve_path(const char *filename, int filename_length, const c return NULL; } + if (strlen(filename) != filename_length) { + return NULL; + } + /* Don't resolve paths which contain protocol (except of file://) */ for (p = filename; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++); if ((*p == ':') && (p - filename > 1) && (p[1] == '/') && (p[2] == '/')) { diff --git a/main/main.c b/main/main.c index 45751ad96..4b52195c9 100644 --- a/main/main.c +++ b/main/main.c @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c 296107 2010-03-12 10:28:59Z jani $ */ +/* $Id: main.c 305266 2010-11-11 01:43:53Z kalle $ */ /* {{{ includes */ @@ -1944,6 +1944,11 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS); +#ifdef ZEND_MULTIBYTE + REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 1, CONST_PERSISTENT | CONST_CS); +#else + REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 0, CONST_PERSISTENT | CONST_CS); +#endif #ifdef PHP_WIN32 REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS); @@ -2076,14 +2081,14 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod while (*p) { if (cfg_get_long((char*)*p, &val) == SUCCESS && val) { - zend_error(E_WARNING, "Directive '%s' is deprecated in PHP 5.3 and greater", *p); + zend_error(E_DEPRECATED, "Directive '%s' is deprecated in PHP 5.3 and greater", *p); } ++p; } /* This is not too nice, but since its the only one theres no need for extra stuff here */ if (cfg_get_long("zend.ze1_compatibility_mode", &val) == SUCCESS && val) { - zend_error(E_ERROR, "zend.ze1_compatibility_mode is no longer supported in PHP 5.3 and greater"); + zend_error(E_CORE_ERROR, "zend.ze1_compatibility_mode is no longer supported in PHP 5.3 and greater"); } } diff --git a/main/network.c b/main/network.c index 542c7cf9e..4e2ce7cdb 100644 --- a/main/network.c +++ b/main/network.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: network.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: network.c 303958 2010-10-02 18:32:20Z cataphract $ */ /*#define DEBUG_MAIN_NETWORK 1*/ @@ -125,7 +125,7 @@ static const char *php_gai_strerror(int code) {EAI_MEMORY, "Memory allocation failure"}, # ifdef EAI_NODATA {EAI_NODATA, "No address associated with hostname"}, -# endif +# endif {EAI_NONAME, "Name or service not known"}, {EAI_SERVICE, "Servname not supported for ai_socktype"}, {EAI_SOCKTYPE, "ai_socktype not supported"}, @@ -139,7 +139,7 @@ static const char *php_gai_strerror(int code) return (char *)values[i].msg; } } - + return "Unknown error"; } /* }}} */ @@ -182,10 +182,10 @@ static int php_network_getaddresses(const char *host, int socktype, struct socka } #if HAVE_GETADDRINFO memset(&hints, '\0', sizeof(hints)); - + hints.ai_family = AF_INET; /* default to regular inet (see below) */ hints.ai_socktype = socktype; - + # if HAVE_IPV6 /* probe for a working IPv6 stack; even if detected as having v6 at compile * time, at runtime some stacks are slow to resolve or have other issues @@ -206,7 +206,7 @@ static int php_network_getaddresses(const char *host, int socktype, struct socka } hints.ai_family = ipv6_borked ? AF_INET : AF_UNSPEC; # endif - + if ((n = getaddrinfo(host, NULL, &hints, &res))) { if (error_string) { spprintf(error_string, 0, "php_network_getaddresses: getaddrinfo failed: %s", PHP_GAI_STRERROR(n)); @@ -228,17 +228,17 @@ static int php_network_getaddresses(const char *host, int socktype, struct socka sai = res; for (n = 1; (sai = sai->ai_next) != NULL; n++) ; - + *sal = safe_emalloc((n + 1), sizeof(*sal), 0); sai = res; sap = *sal; - + do { *sap = emalloc(sai->ai_addrlen); memcpy(*sap, sai->ai_addr, sai->ai_addrlen); sap++; } while ((sai = sai->ai_next) != NULL); - + freeaddrinfo(res); #else if (!inet_aton(host, &in)) { @@ -313,7 +313,7 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, int ret = 0; SET_SOCKET_BLOCKING_MODE(sockfd, orig_flags); - + if ((n = connect(sockfd, addr, addrlen)) != 0) { error = php_socket_errno(); @@ -337,8 +337,18 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, if (n == 0) { goto ok; } - +# ifdef PHP_WIN32 + /* The documentation for connect() says in case of non-blocking connections + * the select function reports success in the writefds set and failure in + * the exceptfds set. Indeed, using PHP_POLLREADABLE results in select + * failing only due to the timeout and not immediately as would be + * expected when a connection is actively refused. This way, + * php_pollfd_for will return a mask with POLLOUT if the connection + * is successful and with POLLPRI otherwise. */ + if ((n = php_pollfd_for(sockfd, POLLOUT|POLLPRI, timeout)) == 0) { +#else if ((n = php_pollfd_for(sockfd, PHP_POLLREADABLE|POLLOUT, timeout)) == 0) { +#endif error = PHP_TIMEOUT_ERROR_VALUE; } @@ -366,9 +376,11 @@ ok: *error_code = error; } - if (error && error_string) { - *error_string = php_socket_strerror(error, NULL, 0); + if (error) { ret = -1; + if (error_string) { + *error_string = php_socket_strerror(error, NULL, 0); + } } return ret; #else @@ -447,14 +459,14 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po if (sa) { /* attempt to bind */ - + #ifdef SO_REUSEADDR { int val = 1; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&val, sizeof(val)); } #endif - + n = bind(sock, sa, socklen); if (n != SOCK_CONN_ERR) { @@ -474,13 +486,13 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po if (error_string) { *error_string = php_socket_strerror(err, NULL, 0); } - + bound: php_network_freeaddresses(psal); - + return sock; - + } /* }}} */ @@ -598,7 +610,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( /* generally not thread safe, but it *is* thread safe under win32 */ buf = inet_ntoa(((struct sockaddr_in*)sa)->sin_addr); if (buf) { - *textaddrlen = spprintf(textaddr, 0, "%s:%d", + *textaddrlen = spprintf(textaddr, 0, "%s:%d", buf, ntohs(((struct sockaddr_in*)sa)->sin_port)); } @@ -608,7 +620,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( case AF_INET6: buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf)); if (buf) { - *textaddrlen = spprintf(textaddr, 0, "%s:%d", + *textaddrlen = spprintf(textaddr, 0, "%s:%d", buf, ntohs(((struct sockaddr_in6*)sa)->sin6_port)); } @@ -639,7 +651,7 @@ PHPAPI void php_network_populate_name_from_sockaddr( } } -PHPAPI int php_network_get_peer_name(php_socket_t sock, +PHPAPI int php_network_get_peer_name(php_socket_t sock, char **textaddr, long *textaddrlen, struct sockaddr **addr, socklen_t *addrlen @@ -648,7 +660,7 @@ PHPAPI int php_network_get_peer_name(php_socket_t sock, php_sockaddr_storage sa; socklen_t sl = sizeof(sa); memset(&sa, 0, sizeof(sa)); - + if (getpeername(sock, (struct sockaddr*)&sa, &sl) == 0) { php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, textaddr, textaddrlen, @@ -659,7 +671,7 @@ PHPAPI int php_network_get_peer_name(php_socket_t sock, return -1; } -PHPAPI int php_network_get_sock_name(php_socket_t sock, +PHPAPI int php_network_get_sock_name(php_socket_t sock, char **textaddr, long *textaddrlen, struct sockaddr **addr, socklen_t *addrlen @@ -668,7 +680,7 @@ PHPAPI int php_network_get_sock_name(php_socket_t sock, php_sockaddr_storage sa; socklen_t sl = sizeof(sa); memset(&sa, 0, sizeof(sa)); - + if (getsockname(sock, (struct sockaddr*)&sa, &sl) == 0) { php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, textaddr, textaddrlen, @@ -703,7 +715,7 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, int error = 0, n; php_sockaddr_storage sa; socklen_t sl; - + n = php_pollfd_for(srvsock, PHP_POLLREADABLE, timeout); if (n == 0) { @@ -724,18 +736,18 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, error = php_socket_errno(); } } - + if (error_code) { *error_code = error; } if (error_string) { *error_string = php_socket_strerror(error, NULL, 0); } - + return clisock; } /* }}} */ - + /* Connect to a remote host using an interruptible connect with optional timeout. @@ -747,7 +759,7 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock, /* {{{ php_network_connect_socket_to_host */ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short port, int socktype, int asynchronous, struct timeval *timeout, char **error_string, - int *error_code, char *bindto, unsigned short bindport + int *error_code, char *bindto, unsigned short bindport TSRMLS_DC) { int num_addrs, n, fatal = 0; @@ -825,7 +837,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short local_address = (struct sockaddr*)in4; local_address_len = sizeof(struct sockaddr_in); - + in4->sin_family = sa->sa_family; in4->sin_port = htons(bindport); if (!inet_aton(bindto, &in4->sin_addr)) { @@ -840,7 +852,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short local_address = (struct sockaddr*)in6; local_address_len = sizeof(struct sockaddr_in6); - + in6->sin6_family = sa->sa_family; in6->sin6_port = htons(bindport); if (inet_pton(AF_INET6, bindto, &in6->sin6_addr) < 1) { @@ -862,7 +874,7 @@ skip_bind: efree(*error_string); *error_string = NULL; } - + n = php_network_connect_socket(sock, sa, socklen, asynchronous, timeout ? &working_timeout : NULL, error_string, error_code); @@ -907,7 +919,7 @@ skip_bind: connected: php_network_freeaddresses(psal); - + return sock; } /* }}} */ @@ -984,7 +996,7 @@ PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize) int free_it = 1; if (!FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, @@ -1065,7 +1077,7 @@ PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC) flags = !block; if (ioctlsocket(socketd, FIONBIO, &flags) == SOCKET_ERROR) { char *error_string; - + error_string = php_socket_strerror(WSAGetLastError(), NULL, 0); php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error_string); efree(error_string); diff --git a/main/output.c b/main/output.c index f7b1e0cf5..681e4ce96 100644 --- a/main/output.c +++ b/main/output.c @@ -1,4 +1,4 @@ -/* +/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: output.c 296107 2010-03-12 10:28:59Z jani $ */ +/* $Id: output.c 305950 2010-12-03 16:04:24Z jani $ */ #include "php.h" #include "ext/standard/head.h" @@ -61,7 +61,7 @@ PHPAPI int php_default_output_func(const char *str, uint str_len TSRMLS_DC) /* {{{ php_output_init_globals */ static void php_output_init_globals(php_output_globals *output_globals_p TSRMLS_DC) { - OG(php_body_write) = php_default_output_func; + OG(php_body_write) = php_default_output_func; OG(php_header_write) = php_default_output_func; OG(implicit_flush) = 0; OG(output_start_filename) = NULL; @@ -69,22 +69,20 @@ static void php_output_init_globals(php_output_globals *output_globals_p TSRMLS_ } /* }}} */ - /* {{{ php_output_startup - Start output layer */ + * Start output layer */ PHPAPI void php_output_startup(void) { #ifdef ZTS ts_allocate_id(&output_globals_id, sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL); -#else +#else php_output_init_globals(&output_globals TSRMLS_CC); #endif } /* }}} */ - /* {{{ php_output_activate - Initilize output global for activation */ + * Initilize output global for activation */ PHPAPI void php_output_activate(TSRMLS_D) { OG(php_body_write) = php_ub_body_write; @@ -97,15 +95,6 @@ PHPAPI void php_output_activate(TSRMLS_D) } /* }}} */ - -/* {{{ php_output_set_status - Toggle output status. Do NOT use in application code, only in SAPIs where appropriate. */ -PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC) -{ - OG(disable_output) = !status; -} -/* }}} */ - /* {{{ php_output_register_constants */ void php_output_register_constants(TSRMLS_D) { @@ -115,12 +104,19 @@ void php_output_register_constants(TSRMLS_D) } /* }}} */ +/* {{{ php_output_set_status + * Toggle output status. Do NOT use in application code, only in SAPIs where appropriate. */ +PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC) +{ + OG(disable_output) = !status; +} +/* }}} */ /* {{{ php_body_write * Write body part */ PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC) { - return OG(php_body_write)(str, str_length TSRMLS_CC); + return OG(php_body_write)(str, str_length TSRMLS_CC); } /* }}} */ @@ -219,7 +215,7 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS fclose(fp); } #endif - + if (OG(active_ob_buffer).internal_output_handler) { final_buffer = OG(active_ob_buffer).internal_output_handler_buffer; final_buffer_length = OG(active_ob_buffer).internal_output_handler_buffer_size; @@ -343,7 +339,7 @@ PHPAPI void php_end_ob_buffers(zend_bool send_buffer TSRMLS_DC) */ PHPAPI void php_start_implicit_flush(TSRMLS_D) { - OG(implicit_flush)=1; + OG(implicit_flush) = 1; } /* }}} */ @@ -351,7 +347,23 @@ PHPAPI void php_start_implicit_flush(TSRMLS_D) */ PHPAPI void php_end_implicit_flush(TSRMLS_D) { - OG(implicit_flush)=0; + OG(implicit_flush) = 0; +} +/* }}} */ + +/* {{{ char *php_get_output_start_filename(TSRMLS_D) + * Return filename start output something */ +PHPAPI char *php_get_output_start_filename(TSRMLS_D) +{ + return OG(output_start_filename); +} +/* }}} */ + +/* {{{ char *php_get_output_start_lineno(TSRMLS_D) + * Return line number start output something */ +PHPAPI int php_get_output_start_lineno(TSRMLS_D) +{ + return OG(output_start_lineno); } /* }}} */ @@ -359,7 +371,7 @@ PHPAPI void php_end_implicit_flush(TSRMLS_D) */ PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size, char *handler_name, zend_bool erase TSRMLS_DC) { - if (OG(ob_nesting_level)==0 || OG(active_ob_buffer).internal_output_handler || strcmp(OG(active_ob_buffer).handler_name, OB_DEFAULT_HANDLER_NAME)) { + if (OG(ob_nesting_level) == 0 || OG(active_ob_buffer).internal_output_handler || strcmp(OG(active_ob_buffer).handler_name, OB_DEFAULT_HANDLER_NAME)) { php_start_ob_buffer(NULL, buffer_size, erase TSRMLS_CC); } @@ -398,8 +410,7 @@ static inline void php_ob_allocate(uint text_length TSRMLS_DC) /* }}} */ /* {{{ php_ob_init_conflict - * Returns 1 if handler_set is already used and generates error message - */ + * Returns 1 if handler_set is already used and generates error message */ PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC) { if (php_ob_handler_used(handler_set TSRMLS_CC)) { @@ -419,7 +430,7 @@ static int php_ob_init_named(uint initial_size, uint block_size, char *handler_n if (output_handler && !zend_is_callable(output_handler, 0, NULL TSRMLS_CC)) { return FAILURE; } - + tmp_buf.block_size = block_size; tmp_buf.size = initial_size; tmp_buf.buffer = (char *) emalloc(initial_size+1); @@ -452,8 +463,7 @@ static int php_ob_init_named(uint initial_size, uint block_size, char *handler_n /* }}} */ /* {{{ php_ob_handler_from_string - * Create zval output handler from string - */ + * Create zval output handler from string */ static zval* php_ob_handler_from_string(const char *handler_name, int len TSRMLS_DC) { zval *output_handler; @@ -544,36 +554,16 @@ static int php_ob_init(uint initial_size, uint block_size, zval *output_handler, /* {{{ php_ob_list_each */ -static int php_ob_list_each(php_ob_buffer *ob_buffer, zval *ob_handler_array) +static int php_ob_list_each(php_ob_buffer *ob_buffer, zval *ob_handler_array) { add_next_index_string(ob_handler_array, ob_buffer->handler_name, 1); return 0; } /* }}} */ -/* {{{ proto false|array ob_list_handlers() - * List all output_buffers in an array - */ -PHP_FUNCTION(ob_list_handlers) -{ - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - array_init(return_value); - if (OG(ob_nesting_level)) { - if (OG(ob_nesting_level)>1) { - zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_ob_list_each, return_value); - } - php_ob_list_each(&OG(active_ob_buffer), return_value); - } -} -/* }}} */ - /* {{{ php_ob_used_each - * Sets handler_name to NULL is found - */ -static int php_ob_handler_used_each(php_ob_buffer *ob_buffer, char **handler_name) + Sets handler_name to NULL is found */ +static int php_ob_handler_used_each(php_ob_buffer *ob_buffer, char **handler_name) { if (!strcmp(ob_buffer->handler_name, *handler_name)) { *handler_name = NULL; @@ -584,8 +574,7 @@ static int php_ob_handler_used_each(php_ob_buffer *ob_buffer, char **handler_nam /* }}} */ /* {{{ php_ob_used - * returns 1 if given handler_name is used as output_handler - */ + returns 1 if given handler_name is used as output_handler */ PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC) { char *tmp = handler_name; @@ -616,10 +605,10 @@ static inline void php_ob_append(const char *text, uint text_length TSRMLS_DC) memcpy(target, text, text_length); target[text_length]=0; - /* If implicit_flush is On or chunked buffering, send contents to next buffer and return. */ + /* If implicit_flush is On or chunked buffering, send contents to next buffer and return. */ if (OG(active_ob_buffer).chunk_size && OG(active_ob_buffer).text_length >= OG(active_ob_buffer).chunk_size) { - + php_end_ob_buffer(1, 1 TSRMLS_CC); return; } @@ -646,7 +635,6 @@ static inline void php_ob_prepend(const char *text, uint text_length) } #endif - /* {{{ php_ob_get_buffer * Return the current output buffer */ PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC) @@ -675,7 +663,6 @@ PHPAPI int php_ob_get_length(zval *p TSRMLS_DC) * Wrapper functions - implementation */ - /* buffered output function */ static int php_b_body_write(const char *str, uint str_length TSRMLS_DC) { @@ -691,7 +678,7 @@ PHPAPI int php_ub_body_write_no_header(const char *str, uint str_length TSRMLS_D if (OG(disable_output)) { return 0; - } + } result = OG(php_header_write)(str, str_length TSRMLS_CC); @@ -733,26 +720,56 @@ PHPAPI int php_ub_body_write(const char *str, uint str_length TSRMLS_DC) } /* }}} */ +/* {{{ int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) + */ +static int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) +{ + zval *elem; + + MAKE_STD_ZVAL(elem); + array_init(elem); + + add_assoc_long(elem, "chunk_size", ob_buffer->chunk_size); + if (!ob_buffer->chunk_size) { + add_assoc_long(elem, "size", ob_buffer->size); + add_assoc_long(elem, "block_size", ob_buffer->block_size); + } + if (ob_buffer->internal_output_handler) { + add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_INTERNAL); + add_assoc_long(elem, "buffer_size", ob_buffer->internal_output_handler_buffer_size); + } else { + add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_USER); + } + add_assoc_long(elem, "status", ob_buffer->status); + add_assoc_string(elem, "name", ob_buffer->handler_name, 1); + add_assoc_bool(elem, "del", ob_buffer->erase); + add_next_index_zval(result, elem); + + return SUCCESS; +} +/* }}} */ + /* - * HEAD support + * USERLAND (nearly 1:1 of old output.c) */ -/* {{{ proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) +/* {{{ proto bool ob_start([string|array user_function [, int chunk_size [, bool erase]]]) Turn on Output Buffering (specifying an optional output handler). */ PHP_FUNCTION(ob_start) { - zval *output_handler=NULL; - long chunk_size=0; - zend_bool erase=1; + zval *output_handler = NULL; + long chunk_size = 0; + zend_bool erase = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zlb", &output_handler, &chunk_size, &erase) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/lb", &output_handler, &chunk_size, &erase) == FAILURE) { return; } - if (chunk_size < 0) + if (chunk_size < 0) { chunk_size = 0; + } - if (php_start_ob_buffer(output_handler, chunk_size, erase TSRMLS_CC)==FAILURE) { + if (php_start_ob_buffer(output_handler, chunk_size, erase TSRMLS_CC) == FAILURE) { RETURN_FALSE; } RETURN_TRUE; @@ -768,21 +785,20 @@ PHP_FUNCTION(ob_flush) } if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush."); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer. No buffer to flush"); RETURN_FALSE; } - + if (!OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer %s.", OG(active_ob_buffer).handler_name); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer %s", OG(active_ob_buffer).handler_name); RETURN_FALSE; } - + php_end_ob_buffer(1, 1 TSRMLS_CC); RETURN_TRUE; } /* }}} */ - /* {{{ proto bool ob_clean(void) Clean (delete) the current output buffer */ PHP_FUNCTION(ob_clean) @@ -790,17 +806,17 @@ PHP_FUNCTION(ob_clean) if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete."); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete"); RETURN_FALSE; } if (!OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s", OG(active_ob_buffer).handler_name); RETURN_FALSE; } - + php_end_ob_buffer(0, 1 TSRMLS_CC); RETURN_TRUE; } @@ -813,16 +829,17 @@ PHP_FUNCTION(ob_end_flush) if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush."); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush"); RETURN_FALSE; } + if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s", OG(active_ob_buffer).handler_name); RETURN_FALSE; } - + php_end_ob_buffer(1, 0 TSRMLS_CC); RETURN_TRUE; } @@ -835,16 +852,17 @@ PHP_FUNCTION(ob_end_clean) if (zend_parse_parameters_none() == FAILURE) { return; } - + if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete."); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete"); RETURN_FALSE; } + if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s", OG(active_ob_buffer).handler_name); RETURN_FALSE; } - + php_end_ob_buffer(0, 0 TSRMLS_CC); RETURN_TRUE; } @@ -858,22 +876,22 @@ PHP_FUNCTION(ob_get_flush) return; } - /* get contents */ - if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) { + if (php_ob_get_buffer(return_value TSRMLS_CC) == FAILURE) { RETURN_FALSE; } - /* error checks */ + if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush."); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete and flush buffer. No buffer to delete or flush"); zval_dtor(return_value); RETURN_FALSE; } + if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s", OG(active_ob_buffer).handler_name); zval_dtor(return_value); RETURN_FALSE; } - /* flush */ + php_end_ob_buffer(1, 0 TSRMLS_CC); } /* }}} */ @@ -885,22 +903,22 @@ PHP_FUNCTION(ob_get_clean) if (zend_parse_parameters_none() == FAILURE) { return; } - /* get contents */ - if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) { + + if (php_ob_get_buffer(return_value TSRMLS_CC) == FAILURE) { RETURN_FALSE; } - /* error checks */ + if (!OG(ob_nesting_level)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete."); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete"); zval_dtor(return_value); RETURN_FALSE; } if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s", OG(active_ob_buffer).handler_name); zval_dtor(return_value); RETURN_FALSE; } - /* delete buffer */ + php_end_ob_buffer(0, 0 TSRMLS_CC); } /* }}} */ @@ -912,8 +930,8 @@ PHP_FUNCTION(ob_get_contents) if (zend_parse_parameters_none() == FAILURE) { return; } - - if (php_ob_get_buffer(return_value TSRMLS_CC)==FAILURE) { + + if (php_ob_get_buffer(return_value TSRMLS_CC) == FAILURE) { RETURN_FALSE; } } @@ -926,8 +944,8 @@ PHP_FUNCTION(ob_get_level) if (zend_parse_parameters_none() == FAILURE) { return; } - - RETURN_LONG (OG(ob_nesting_level)); + + RETURN_LONG(OG(ob_nesting_level)); } /* }}} */ @@ -938,63 +956,52 @@ PHP_FUNCTION(ob_get_length) if (zend_parse_parameters_none() == FAILURE) { return; } - - if (php_ob_get_length(return_value TSRMLS_CC)==FAILURE) { + + if (php_ob_get_length(return_value TSRMLS_CC) == FAILURE) { RETURN_FALSE; } } /* }}} */ -/* {{{ int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) */ -static int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) +/* {{{ proto false|array ob_list_handlers() + List all output_buffers in an array */ +PHP_FUNCTION(ob_list_handlers) { - zval *elem; + if (zend_parse_parameters_none() == FAILURE) { + return; + } - MAKE_STD_ZVAL(elem); - array_init(elem); + array_init(return_value); - add_assoc_long(elem, "chunk_size", ob_buffer->chunk_size); - if (!ob_buffer->chunk_size) { - add_assoc_long(elem, "size", ob_buffer->size); - add_assoc_long(elem, "block_size", ob_buffer->block_size); - } - if (ob_buffer->internal_output_handler) { - add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_INTERNAL); - add_assoc_long(elem, "buffer_size", ob_buffer->internal_output_handler_buffer_size); - } - else { - add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_USER); + if (OG(ob_nesting_level)) { + if (OG(ob_nesting_level) > 1) { + zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_ob_list_each, return_value); + } + php_ob_list_each(&OG(active_ob_buffer), return_value); } - add_assoc_long(elem, "status", ob_buffer->status); - add_assoc_string(elem, "name", ob_buffer->handler_name, 1); - add_assoc_bool(elem, "del", ob_buffer->erase); - add_next_index_zval(result, elem); - - return SUCCESS; } /* }}} */ - /* {{{ proto false|array ob_get_status([bool full_status]) Return the status of the active or all output buffers */ PHP_FUNCTION(ob_get_status) { zend_bool full_status = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_status) == FAILURE ) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_status) == FAILURE) { return; } array_init(return_value); if (full_status) { - if (OG(ob_nesting_level)>1) { + if (OG(ob_nesting_level) > 1) { zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *elem, void *))php_ob_buffer_status, return_value); } - if (OG(ob_nesting_level)>0 && php_ob_buffer_status(&OG(active_ob_buffer), return_value)==FAILURE) { + if (OG(ob_nesting_level) > 0 && php_ob_buffer_status(&OG(active_ob_buffer), return_value) == FAILURE) { RETURN_FALSE; } - } else if (OG(ob_nesting_level)>0) { + } else if (OG(ob_nesting_level) > 0) { add_assoc_long(return_value, "level", OG(ob_nesting_level)); if (OG(active_ob_buffer).internal_output_handler) { add_assoc_long(return_value, "type", PHP_OUTPUT_HANDLER_INTERNAL); @@ -1008,7 +1015,6 @@ PHP_FUNCTION(ob_get_status) } /* }}} */ - /* {{{ proto void ob_implicit_flush([int flag]) Turn implicit flush on/off and is equivalent to calling flush() after every output call */ PHP_FUNCTION(ob_implicit_flush) @@ -1027,25 +1033,6 @@ PHP_FUNCTION(ob_implicit_flush) } /* }}} */ - -/* {{{ char *php_get_output_start_filename(TSRMLS_D) - Return filename start output something */ -PHPAPI char *php_get_output_start_filename(TSRMLS_D) -{ - return OG(output_start_filename); -} -/* }}} */ - - -/* {{{ char *php_get_output_start_lineno(TSRMLS_D) - Return line number start output something */ -PHPAPI int php_get_output_start_lineno(TSRMLS_D) -{ - return OG(output_start_lineno); -} -/* }}} */ - - /* {{{ proto bool output_reset_rewrite_vars(void) Reset(clear) URL rewriter values */ PHP_FUNCTION(output_reset_rewrite_vars) @@ -1058,7 +1045,6 @@ PHP_FUNCTION(output_reset_rewrite_vars) } /* }}} */ - /* {{{ proto bool output_add_rewrite_var(string name, string value) Add URL rewriter values */ PHP_FUNCTION(output_add_rewrite_var) diff --git a/main/php_config.h.in b/main/php_config.h.in index d62d83677..ff2e50398 100644 --- a/main/php_config.h.in +++ b/main/php_config.h.in @@ -467,6 +467,9 @@ /* Define if you have the setpriority function. */ #undef HAVE_SETPRIORITY +/* Define if you have the setproctitle function. */ +#undef HAVE_SETPROCTITLE + /* Define if you have the setsid function. */ #undef HAVE_SETSID @@ -953,9 +956,6 @@ /* Whether you have a Continuity Server */ #undef HAVE_CONTINUITY -/* define if libevent is available */ -#undef HAVE_LIBEVENT - /* do we have prctl? */ #undef HAVE_PRCTL @@ -974,8 +974,14 @@ /* /proc/pid/mem interface */ #undef PROC_MEM_FILE -/* fpm version */ -#undef PHP_FPM_VERSION +/* Define to 1 if gcc supports __sync_bool_compare_and_swap() a.o. */ +#undef HAVE_BUILTIN_ATOMIC + +/* do we have TCP_INFO? */ +#undef HAVE_LQ_TCP_INFO + +/* do we have SO_LISTENQxxx? */ +#undef HAVE_LQ_SO_LISTENQ /* fpm user name */ #undef PHP_FPM_USER @@ -1173,9 +1179,6 @@ #undef HAVE_NANOSLEEP /* */ -#undef HAVE_NANOSLEEP - -/* */ #undef HAVE_LIBRT /* Define if you have the getaddrinfo function */ diff --git a/main/php_ini.c b/main/php_ini.c index 13ed8a5ba..ff7adaf69 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_ini.c 300272 2010-06-08 12:54:11Z tony2001 $ */ +/* $Id: php_ini.c 303199 2010-09-09 05:11:05Z aharvey $ */ #include "php.h" #include "ext/standard/info.h" @@ -201,6 +201,7 @@ PHPAPI void config_zval_dtor(zval *zvalue) /* Reset / free active_ini_sectin global */ #define RESET_ACTIVE_INI_HASH() do { \ active_ini_hash = NULL; \ + is_special_section = 0; \ } while (0) /* }}} */ @@ -398,13 +399,39 @@ int php_init_config(TSRMLS_D) static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 }; #ifdef PHP_WIN32 char *reg_location; + char phprc_path[MAXPATHLEN]; #endif env_location = getenv("PHPRC"); + +#ifdef PHP_WIN32 + if (!env_location) { + char dummybuf; + int size; + + SetLastError(0); + + /*If the given bugger is not large enough to hold the data, the return value is + the buffer size, in characters, required to hold the string and its terminating + null character. We use this return value to alloc the final buffer. */ + size = GetEnvironmentVariableA("PHPRC", &dummybuf, 0); + if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) { + /* The environment variable doesn't exist. */ + env_location = ""; + } else { + if (size == 0) { + env_location = ""; + } else { + size = GetEnvironmentVariableA("PHPRC", phprc_path, size); + env_location = phprc_path; + } + } + } +#else if (!env_location) { env_location = ""; } - +#endif /* * Prepare search path */ @@ -628,9 +655,6 @@ int php_init_config(TSRMLS_D) zend_llist_element *element; int l, total_l = 0; - /* Reset active ini section */ - RESET_ACTIVE_INI_HASH(); - if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) { zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1); memset(&fh, 0, sizeof(fh)); @@ -642,6 +666,9 @@ int php_init_config(TSRMLS_D) free(namelist[i]); continue; } + /* Reset active ini section */ + RESET_ACTIVE_INI_HASH(); + if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) { snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name); } else { diff --git a/main/php_streams.h b/main/php_streams.h index 2da3a5f2e..c4967813e 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams.h 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: php_streams.h 305108 2010-11-05 18:53:48Z cataphract $ */ #ifndef PHP_STREAMS_H #define PHP_STREAMS_H @@ -416,8 +416,8 @@ END_EXTERN_C() #define PHP_STREAM_OPTION_RETURN_ERR -1 /* problem setting option */ #define PHP_STREAM_OPTION_RETURN_NOTIMPL -2 /* underlying stream does not implement; streams can handle it instead */ -/* copy up to maxlen bytes from src to dest. If maxlen is PHP_STREAM_COPY_ALL, copy until eof(src). - * Uses mmap if the src is a plain file and at offset 0 */ +/* copy up to maxlen bytes from src to dest. If maxlen is PHP_STREAM_COPY_ALL, + * copy until eof(src). */ #define PHP_STREAM_COPY_ALL ((size_t)-1) BEGIN_EXTERN_C() @@ -428,8 +428,8 @@ PHPAPI size_t _php_stream_copy_to_stream_ex(php_stream *src, php_stream *dest, s #define php_stream_copy_to_stream_ex(src, dest, maxlen, len) _php_stream_copy_to_stream_ex((src), (dest), (maxlen), (len) STREAMS_CC TSRMLS_CC) -/* read all data from stream and put into a buffer. Caller must free buffer when done. - * The copy will use mmap if available. */ +/* read all data from stream and put into a buffer. Caller must free buffer + * when done. */ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC); #define php_stream_copy_to_mem(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC) diff --git a/main/php_version.h b/main/php_version.h index 7be2a1bd6..75b2a8de1 100644 --- a/main/php_version.h +++ b/main/php_version.h @@ -2,7 +2,7 @@ /* edit configure.in to change version number */ #define PHP_MAJOR_VERSION 5 #define PHP_MINOR_VERSION 3 -#define PHP_RELEASE_VERSION 3 +#define PHP_RELEASE_VERSION 5 #define PHP_EXTRA_VERSION "" -#define PHP_VERSION "5.3.3" -#define PHP_VERSION_ID 50303 +#define PHP_VERSION "5.3.5" +#define PHP_VERSION_ID 50305 diff --git a/main/rfc1867.c b/main/rfc1867.c index 351c54fd8..f10395dc1 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: rfc1867.c 296362 2010-03-18 22:37:25Z andrei $ */ +/* $Id: rfc1867.c 303970 2010-10-04 01:27:33Z cataphract $ */ /* * This product includes software developed by the Apache Group @@ -1011,16 +1011,8 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } total_bytes = cancel_upload = 0; - - if (!skip_upload) { - /* Handle file */ - fd = php_open_temporary_fd_ex(PG(upload_tmp_dir), "php", &temp_filename, 1 TSRMLS_CC); - upload_cnt--; - if (fd == -1) { - sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file"); - cancel_upload = UPLOAD_ERROR_E; - } - } + temp_filename = NULL; + fd = -1; if (!skip_upload && php_rfc1867_callback != NULL) { multipart_event_file_start event_file_start; @@ -1029,13 +1021,6 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ event_file_start.name = param; event_file_start.filename = &filename; if (php_rfc1867_callback(MULTIPART_EVENT_FILE_START, &event_file_start, &event_extra_data TSRMLS_CC) == FAILURE) { - if (temp_filename) { - if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */ - close(fd); - unlink(temp_filename); - } - efree(temp_filename); - } temp_filename = ""; efree(param); efree(filename); @@ -1058,7 +1043,26 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ offset = 0; end = 0; - while (!cancel_upload && (blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC))) + + if (!cancel_upload) { + /* only bother to open temp file if we have data */ + blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC); +#if DEBUG_FILE_UPLOAD + if (blen > 0) { +#else + /* in non-debug mode we have no problem with 0-length files */ + { +#endif + fd = php_open_temporary_fd_ex(PG(upload_tmp_dir), "php", &temp_filename, 1 TSRMLS_CC); + upload_cnt--; + if (fd == -1) { + sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file"); + cancel_upload = UPLOAD_ERROR_E; + } + } + } + + while (!cancel_upload && (blen > 0)) { if (php_rfc1867_callback != NULL) { multipart_event_file_data event_file_data; @@ -1103,10 +1107,15 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ } offset += wlen; } + + /* read data for next iteration */ + blen = multipart_buffer_read(mbuff, buff, sizeof(buff), &end TSRMLS_CC); } + if (fd != -1) { /* may not be initialized if file could not be created */ close(fd); } + if (!cancel_upload && !end) { #if DEBUG_FILE_UPLOAD sapi_module.sapi_error(E_NOTICE, "Missing mime boundary at the end of the data for file %s", strlen(filename) > 0 ? filename : ""); diff --git a/main/streams/cast.c b/main/streams/cast.c index 91174665b..85136f016 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: cast.c 293732 2010-01-19 13:44:08Z jani $ */ +/* $Id: cast.c 305108 2010-11-05 18:53:48Z cataphract $ */ #define _GNU_SOURCE #include "php.h" @@ -144,6 +144,50 @@ static COOKIE_IO_FUNCTIONS_T stream_cookie_functions = #endif /* }}} */ +/* {{{ php_stream_mode_sanitize_fdopen_fopencookie + * Result should have at least size 5, e.g. to write wbx+\0 */ +void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *result) +{ + /* replace modes not supported by fdopen and fopencookie, but supported + * by PHP's fread(), so that their calls won't fail */ + const char *cur_mode = stream->mode; + int has_plus = 0, + has_bin = 0, + i, + res_curs = 0; + + if (cur_mode[0] == 'r' || cur_mode[0] == 'w' || cur_mode[0] == 'a') { + result[res_curs++] = cur_mode[0]; + } else { + /* assume cur_mode[0] is 'c' or 'x'; substitute by 'w', which should not + * truncate anything in fdopen/fopencookie */ + result[res_curs++] = 'w'; + + /* x is allowed (at least by glibc & compat), but not as the 1st mode + * as in PHP and in any case is (at best) ignored by fdopen and fopencookie */ + } + + /* assume current mode has at most length 4 (e.g. wbn+) */ + for (i = 1; i < 4 && cur_mode[i] != '\0'; i++) { + if (cur_mode[i] == 'b') { + has_bin = 1; + } else if (cur_mode[i] == '+') { + has_plus = 1; + } + /* ignore 'n', 't' or other stuff */ + } + + if (has_bin) { + result[res_curs++] = 'b'; + } + if (has_plus) { + result[res_curs++] = '+'; + } + + result[res_curs] = '\0'; +} +/* }}} */ + /* {{{ php_stream_cast */ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC) { @@ -187,7 +231,11 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show goto exit_success; } - *(FILE**)ret = fopencookie(stream, stream->mode, PHP_STREAM_COOKIE_FUNCTIONS); + { + char fixed_mode[5]; + php_stream_mode_sanitize_fdopen_fopencookie(stream, fixed_mode); + *(FILE**)ret = fopencookie(stream, fixed_mode, PHP_STREAM_COOKIE_FUNCTIONS); + } if (*ret != NULL) { off_t pos; diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index cf5976738..e3c31adb4 100755 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: glob_wrapper.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: glob_wrapper.c 303265 2010-09-10 21:33:50Z felipe $ */ #include "php.h" #include "php_streams_int.h" @@ -29,6 +29,7 @@ # endif #endif +#ifdef HAVE_GLOB #ifndef GLOB_ONLYDIR #define GLOB_ONLYDIR (1<<30) #define GLOB_FLAGMASK (~GLOB_ONLYDIR) @@ -278,6 +279,7 @@ php_stream_wrapper php_glob_stream_wrapper = { NULL, 0 }; +#endif /* HAVE_GLOB */ /* * Local variables: diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h index 113c518aa..e97247724 100644 --- a/main/streams/php_streams_int.h +++ b/main/streams/php_streams_int.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_streams_int.h 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: php_streams_int.h 305108 2010-11-05 18:53:48Z cataphract $ */ #if ZEND_DEBUG @@ -59,6 +59,13 @@ #define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG) #endif +/* This functions transforms the first char to 'w' if it's not 'r', 'a' or 'w' + * and strips any subsequent chars except '+' and 'b'. + * Use this to sanitize stream->mode if you call e.g. fdopen, fopencookie or + * any other function that expects standard modes and you allow non-standard + * ones. result should be a char[5]. */ +void php_stream_mode_sanitize_fdopen_fopencookie(php_stream *stream, char *result); + void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC); void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char *path, const char *caption TSRMLS_DC); diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 2087505ce..6cd8559a0 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: plain_wrapper.c 295308 2010-02-21 17:44:25Z pajoye $ */ +/* $Id: plain_wrapper.c 305108 2010-11-05 18:53:48Z cataphract $ */ #include "php.h" #include "php_globals.h" @@ -490,7 +490,9 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC) if (data->file == NULL) { /* we were opened as a plain file descriptor, so we * need fdopen now */ - data->file = fdopen(data->fd, stream->mode); + char fixed_mode[5]; + php_stream_mode_sanitize_fdopen_fopencookie(stream, fixed_mode); + data->file = fdopen(data->fd, fixed_mode); if (data->file == NULL) { return FAILURE; } @@ -1017,10 +1019,18 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, char *url, in return -1; } -#ifdef HAVE_SYMLINK +#ifdef PHP_WIN32 + if (EG(windows_version_info).dwMajorVersion >= 5) { + if (flags & PHP_STREAM_URL_STAT_LINK) { + return VCWD_LSTAT(url, &ssb->sb); + } + } +#else +# ifdef HAVE_SYMLINK if (flags & PHP_STREAM_URL_STAT_LINK) { return VCWD_LSTAT(url, &ssb->sb); } else +# endif #endif return VCWD_STAT(url, &ssb->sb); } @@ -1139,7 +1149,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c #else php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno)); #endif - return 0; + return 0; } /* Clear stat cache (and realpath cache) */ @@ -1221,7 +1231,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod if (*p == '\0') { *p = DEFAULT_SLASH; if ((*(p+1) != '\0') && - (ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) { + (ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) { if (options & REPORT_ERRORS) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); } @@ -1298,7 +1308,6 @@ PHPAPI php_stream *_php_stream_fopen_with_path(char *filename, char *mode, char char *pathbuf, *ptr, *end; char *exec_fname; char trypath[MAXPATHLEN]; - struct stat sb; php_stream *stream; int path_length; int filename_length; @@ -1440,6 +1449,8 @@ not_relative_path: } if (PG(safe_mode)) { + struct stat sb; + if (VCWD_STAT(trypath, &sb) == 0) { /* file exists ... check permission */ if ((php_check_safe_mode_include_dir(trypath TSRMLS_CC) == 0) || diff --git a/main/streams/streams.c b/main/streams/streams.c index e3f79816a..e19430608 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c 299466 2010-05-18 19:39:39Z pajoye $ */ +/* $Id: streams.c 305379 2010-11-15 18:22:52Z cataphract $ */ #define _GNU_SOURCE #include "php.h" @@ -1093,12 +1093,17 @@ PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC) PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC) { + if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) { + /* flush to commit data written to the fopencookie FILE* */ + fflush(stream->stdiocast); + } + /* handle the case where we are in the buffer */ if ((stream->flags & PHP_STREAM_FLAG_NO_BUFFER) == 0) { switch(whence) { case SEEK_CUR: - if (offset > 0 && offset < stream->writepos - stream->readpos) { - stream->readpos += offset; + if (offset > 0 && offset <= stream->writepos - stream->readpos) { + stream->readpos += offset; /* if offset = ..., then readpos = writepos */ stream->position += offset; stream->eof = 0; return 0; @@ -1106,7 +1111,7 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_ break; case SEEK_SET: if (offset > stream->position && - offset < stream->position + stream->writepos - stream->readpos) { + offset <= stream->position + stream->writepos - stream->readpos) { stream->readpos += offset - stream->position; stream->position = offset; stream->eof = 0; @@ -1149,14 +1154,12 @@ PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_ /* emulate forward moving seeks with reads */ if (whence == SEEK_CUR && offset > 0) { char tmp[1024]; - while(offset >= sizeof(tmp)) { - if (php_stream_read(stream, tmp, sizeof(tmp)) == 0) { + size_t didread; + while(offset > 0) { + if ((didread = php_stream_read(stream, tmp, MIN(offset, sizeof(tmp)))) == 0) { return -1; } - offset -= sizeof(tmp); - } - if (offset && (php_stream_read(stream, tmp, offset) == 0)) { - return -1; + offset -= didread; } stream->eof = 0; return 0; diff --git a/main/win95nt.h b/main/win95nt.h index d88f0631b..bfca2d551 100644 --- a/main/win95nt.h +++ b/main/win95nt.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: win95nt.h 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: win95nt.h 305778 2010-11-26 18:25:13Z pajoye $ */ /* Defines and types for Windows 95/NT */ #define HAVE_DECLARED_TIMEZONE @@ -33,7 +33,7 @@ typedef int uid_t; typedef int gid_t; typedef char * caddr_t; -#define lstat(x, y) stat(x, y) +#define lstat(x, y) php_sys_lstat(x, y) #define _IFIFO 0010000 /* fifo */ #define _IFBLK 0060000 /* block special */ #define _IFLNK 0120000 /* symbolic link */ @@ -47,7 +47,7 @@ typedef char * caddr_t; #define mkdir(a, b) _mkdir(a) #define rmdir(a) _rmdir(a) #define getpid _getpid -#define php_sleep(t) Sleep(t*1000) +#define php_sleep(t) SleepEx(t*1000, TRUE) #ifndef getcwd # define getcwd(a, b) _getcwd(a, b) #endif |
