diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/SAPI.c | 45 | ||||
-rw-r--r-- | main/SAPI.h | 7 | ||||
-rw-r--r-- | main/main.c | 14 | ||||
-rw-r--r-- | main/network.c | 8 | ||||
-rw-r--r-- | main/php.h | 7 | ||||
-rw-r--r-- | main/php_compat.h | 44 | ||||
-rw-r--r-- | main/php_scandir.c | 4 | ||||
-rw-r--r-- | main/php_scandir.h | 4 | ||||
-rw-r--r-- | main/php_version.h | 4 | ||||
-rw-r--r-- | main/rfc1867.c | 52 | ||||
-rw-r--r-- | main/snprintf.c | 41 | ||||
-rw-r--r-- | main/snprintf.h | 10 | ||||
-rw-r--r-- | main/streams/filter.c | 15 | ||||
-rwxr-xr-x | main/streams/glob_wrapper.c | 7 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 1 | ||||
-rwxr-xr-x | main/streams/streams.c | 35 | ||||
-rw-r--r-- | main/streams/userspace.c | 205 | ||||
-rw-r--r-- | main/streams/xp_socket.c | 8 |
18 files changed, 114 insertions, 397 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index 3adb76541e..feabcef549 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -497,8 +497,7 @@ static void sapi_update_response_code(int ncode TSRMLS_DC) static int sapi_find_matching_header(void *element1, void *element2) { - int len = strlen((char*)element2); - return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2, len) == 0 && ((sapi_header_struct*)element1)->header[len] == ':'; + return strncasecmp(((sapi_header_struct*)element1)->header, (char*)element2, strlen((char*)element2)) == 0; } SAPI_API int sapi_add_header_ex(char *header_line, uint header_line_len, zend_bool duplicate, zend_bool replace TSRMLS_DC) @@ -526,6 +525,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) long myuid = 0L; char *header_line; uint header_line_len; + zend_bool replace; int http_response_code; if (SG(headers_sent) && !SG(request_info).no_headers) { @@ -546,9 +546,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) sapi_update_response_code((int)(zend_intptr_t) arg TSRMLS_CC); return SUCCESS; - case SAPI_HEADER_ADD: case SAPI_HEADER_REPLACE: - case SAPI_HEADER_DELETE: { + case SAPI_HEADER_ADD: { sapi_header_line *p = arg; if (!p->line || !p->line_len) { @@ -557,16 +556,10 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) header_line = p->line; header_line_len = p->line_len; http_response_code = p->response_code; + replace = (op == SAPI_HEADER_REPLACE); break; } - case SAPI_HEADER_DELETE_ALL: - if (sapi_module.header_handler) { - sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC); - } - zend_llist_clean(&SG(sapi_headers).headers); - return SUCCESS; - default: return FAILURE; } @@ -577,14 +570,8 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) while(header_line_len && isspace(header_line[header_line_len-1])) header_line[--header_line_len]='\0'; - if (op == SAPI_HEADER_DELETE) { - if (strchr(header_line, ':')) { - efree(header_line); - sapi_module.sapi_error(E_WARNING, "Header to delete may not contain colon."); - return FAILURE; - } - } else { - /* new line safety check */ + /* new line safety check */ + { char *s = header_line, *e = header_line + header_line_len, *p; while (s < e && (p = memchr(s, '\n', (e - s)))) { if (*(p + 1) == ' ' || *(p + 1) == '\t') { @@ -599,15 +586,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) sapi_header.header = header_line; sapi_header.header_len = header_line_len; - - if (op == SAPI_HEADER_DELETE) { - if (sapi_module.header_handler) { - sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC); - } - zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*, void*))sapi_find_matching_header); - sapi_free_header(&sapi_header); - return SUCCESS; - } + sapi_header.replace = replace; /* Check the header for a few cases that we have special support for in SAPI */ if (header_line_len>=5 @@ -749,16 +728,20 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) sapi_update_response_code(http_response_code TSRMLS_CC); } if (sapi_module.header_handler) { - retval = sapi_module.header_handler(&sapi_header, op, &SG(sapi_headers) TSRMLS_CC); + retval = sapi_module.header_handler(&sapi_header, &SG(sapi_headers) TSRMLS_CC); } else { retval = SAPI_HEADER_ADD; } + if (retval & SAPI_HEADER_DELETE_ALL) { + zend_llist_clean(&SG(sapi_headers).headers); + } if (retval & SAPI_HEADER_ADD) { /* in replace mode first remove the header if it already exists in the headers llist */ - if (op == SAPI_HEADER_REPLACE) { + if (replace) { colon_offset = strchr(sapi_header.header, ':'); if (colon_offset) { char sav; + colon_offset++; sav = *colon_offset; *colon_offset = 0; zend_llist_del_element(&SG(sapi_headers).headers, sapi_header.header, (int(*)(void*, void*))sapi_find_matching_header); @@ -767,8 +750,6 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC) } zend_llist_add_element(&SG(sapi_headers).headers, (void *) &sapi_header); - } else { - sapi_free_header(&sapi_header); } return SUCCESS; } diff --git a/main/SAPI.h b/main/SAPI.h index 1a2adbf10c..d4a558e3e7 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -50,6 +50,7 @@ typedef struct { char *header; uint header_len; + zend_bool replace; } sapi_header_struct; @@ -169,8 +170,6 @@ typedef struct { typedef enum { /* Parameter: */ SAPI_HEADER_REPLACE, /* sapi_header_line* */ SAPI_HEADER_ADD, /* sapi_header_line* */ - SAPI_HEADER_DELETE, /* sapi_header_line* */ - SAPI_HEADER_DELETE_ALL, /* void */ SAPI_HEADER_SET_STATUS /* int */ } sapi_header_op_enum; @@ -228,7 +227,7 @@ struct _sapi_module_struct { void (*sapi_error)(int type, const char *error_msg, ...); - int (*header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC); + int (*header_handler)(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC); int (*send_headers)(sapi_headers_struct *sapi_headers TSRMLS_DC); void (*send_header)(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC); @@ -276,6 +275,8 @@ struct _sapi_post_entry { /* header_handler() constants */ #define SAPI_HEADER_ADD (1<<0) +#define SAPI_HEADER_DELETE_ALL (1<<1) +#define SAPI_HEADER_SEND_NOW (1<<2) #define SAPI_HEADER_SENT_SUCCESSFULLY 1 diff --git a/main/main.c b/main/main.c index df91aa2615..9648b04a0a 100644 --- a/main/main.c +++ b/main/main.c @@ -575,8 +575,8 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c char *docref_target = "", *docref_root = ""; char *p; int buffer_len = 0; - char *space = ""; - char *class_name = ""; + char *space; + char *class_name = get_active_class_name(&space TSRMLS_CC); char *function; int origin_len; char *origin; @@ -632,7 +632,6 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c function = "Unknown"; } else { is_function = 1; - class_name = get_active_class_name(&space TSRMLS_CC); } } @@ -1122,7 +1121,7 @@ static char *php_resolve_path_for_zend(const char *filename, int filename_len TS /* {{{ php_get_configuration_directive_for_zend */ -static int php_get_configuration_directive_for_zend(const char *name, uint name_length, zval *contents) +static int php_get_configuration_directive_for_zend(char *name, uint name_length, zval *contents) { zval *retval = cfg_get_entry(name, name_length); @@ -1478,12 +1477,7 @@ void php_request_shutdown(void *dummy) /* 3. Flush all output buffers */ zend_try { - zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1; - if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR && - OG(ob_nesting_level) && !OG(active_ob_buffer).chunk_size && PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)) { - send_buffer = 0; - } - php_end_ob_buffers(send_buffer TSRMLS_CC); + php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1) TSRMLS_CC); } zend_end_try(); /* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */ diff --git a/main/network.c b/main/network.c index a21e8a5ee6..d8824fd81e 100644 --- a/main/network.c +++ b/main/network.c @@ -647,7 +647,6 @@ 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, @@ -667,7 +666,6 @@ 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, @@ -1059,11 +1057,7 @@ PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC) /* with ioctlsocket, a non-zero sets nonblocking, a zero sets blocking */ 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); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", WSAGetLastError()); ret = FAILURE; } #else diff --git a/main/php.h b/main/php.h index 3ba1317966..f2fb416231 100644 --- a/main/php.h +++ b/main/php.h @@ -173,13 +173,6 @@ typedef unsigned int socklen_t; # endif #endif -#ifndef va_copy -# ifdef __va_copy -# define va_copy(ap1, ap2) __va_copy((ap1), (ap2)) -# else -# define va_copy(ap1, ap2) memcpy((&ap1), (&ap2), sizeof(va_list)) -# endif -#endif #include "zend_hash.h" #include "php3_compat.h" diff --git a/main/php_compat.h b/main/php_compat.h index 65f7572f62..34f8816960 100644 --- a/main/php_compat.h +++ b/main/php_compat.h @@ -28,30 +28,32 @@ #endif #if defined(HAVE_BUNDLED_PCRE) || !defined(PHP_VERSION) -#define pcre_compile php_pcre_compile -#define pcre_compile2 php_pcre_compile2 +#define pcre_compile php_pcre_compile +#define pcre_compile2 php_pcre_compile2 #define pcre_copy_substring php_pcre_copy_substring -#define pcre_exec php_pcre_exec +#define pcre_exec php_pcre_exec #define pcre_get_substring php_pcre_get_substring -#define pcre_get_substring_list php_pcre_get_substring_list -#define pcre_info php_pcre_info +#define pcre_get_substring_list php_pcre_get_substring_list +#define pcre_info php_pcre_info #define pcre_maketables php_pcre_maketables -#define pcre_study php_pcre_study +#define pcre_study php_pcre_study #define pcre_version php_pcre_version #define pcre_fullinfo php_pcre_fullinfo -#define pcre_free php_pcre_free -#define pcre_malloc php_pcre_malloc -#define pcre_config php_pcre_config -#define pcre_copy_named_substring php_pcre_copy_named_substring -#define pcre_free_substring php_pcre_free_substring -#define pcre_free_substring_list php_pcre_free_substring_list -#define pcre_get_named_substring php_pcre_get_named_substring -#define pcre_get_stringnumber php_pcre_get_stringnumber -#define pcre_refcount php_pcre_refcount -#define _pcre_ord2utf8 php__pcre_ord2utf8 -#define _pcre_try_flipped php__pcre_try_flipped -#define _pcre_valid_utf8 php__pcre_valid_utf8 -#define _pcre_xclass php__pcre_xclass +#define pcre_free php_pcre_free +#define pcre_malloc php_pcre_malloc +#define pcre_config php_pcre_config +#define pcre_copy_named_substring php_pcre_copy_named_substring +#define pcre_free_substring php_pcre_free_substring +#define pcre_free_substring_list php_pcre_free_substring_list +#define pcre_get_named_substring php_pcre_get_named_substring +#define pcre_get_stringnumber php_pcre_get_stringnumber +#define pcre_refcount php_pcre_refcount +#define _pcre_ord2utf8 php__pcre_ord2utf8 +#define _pcre_try_flipped php__pcre_try_flipped +#define _pcre_ucp_findprop php__pcre_ucp_findprop +#define _pcre_ucp_othercase php__pcre_ucp_othercase +#define _pcre_valid_utf8 php__pcre_valid_utf8 +#define _pcre_xclass php__pcre_xclass #define pcre_callout php_pcre_callout #define _pcre_OP_lengths php__pcre_OP_lengths #define _pcre_utt_names php__pcre_utt_names @@ -68,10 +70,6 @@ #define _pcre_utt php__pcre_utt #define _pcre_utt_size php__pcre_utt_size #define _pcre_was_newline php__pcre_was_newline -#define _pcre_ucd_records php__pcre_ucd_records -#define _pcre_ucd_stage1 php__pcre_ucd_stage1 -#define _pcre_ucd_stage2 php__pcre_ucd_stage2 -#define _pcre_ucp_gentype php__pcre_ucp_gentype #endif #define lookup php_lookup diff --git a/main/php_scandir.c b/main/php_scandir.c index 8dd218d156..320d108224 100644 --- a/main/php_scandir.c +++ b/main/php_scandir.c @@ -50,14 +50,14 @@ #include <string.h> #endif -PHPAPI int php_alphasort(const struct dirent **a, const struct dirent **b) +int php_alphasort(const struct dirent **a, const struct dirent **b) { return strcoll((*a)->d_name,(*b)->d_name); } #endif /* HAVE_ALPHASORT */ #ifndef HAVE_SCANDIR -PHPAPI int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector) (const struct dirent *entry), int (*compare) (const struct dirent **a, const struct dirent **b)) +int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector) (const struct dirent *entry), int (*compare) (const struct dirent **a, const struct dirent **b)) { DIR *dirp = NULL; struct dirent **vector = NULL; diff --git a/main/php_scandir.h b/main/php_scandir.h index c3b6f0a7c1..5c6584c616 100644 --- a/main/php_scandir.h +++ b/main/php_scandir.h @@ -42,13 +42,13 @@ #ifdef HAVE_SCANDIR #define php_scandir scandir #else -PHPAPI int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector) (const struct dirent *entry), int (*compare) (const struct dirent **a, const struct dirent **b)); +int php_scandir(const char *dirname, struct dirent **namelist[], int (*selector) (const struct dirent *entry), int (*compare) (const struct dirent **a, const struct dirent **b)); #endif #ifdef HAVE_ALPHASORT #define php_alphasort alphasort #else -PHPAPI int php_alphasort(const struct dirent **a, const struct dirent **b); +int php_alphasort(const struct dirent **a, const struct dirent **b); #endif #endif /* PHP_SCANDIR_H */ diff --git a/main/php_version.h b/main/php_version.h index ba026676a0..91db86fd5b 100644 --- a/main/php_version.h +++ b/main/php_version.h @@ -3,6 +3,6 @@ #define PHP_MAJOR_VERSION 5 #define PHP_MINOR_VERSION 3 #define PHP_RELEASE_VERSION 0 -#define PHP_EXTRA_VERSION "alpha3-dev" -#define PHP_VERSION "5.3.0alpha3-dev" +#define PHP_EXTRA_VERSION "alpha2" +#define PHP_VERSION "5.3.0alpha2" #define PHP_VERSION_ID 50300 diff --git a/main/rfc1867.c b/main/rfc1867.c index 828b432c1f..1eda4f94c2 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -203,8 +203,7 @@ static void normalize_protected_variable(char *varname TSRMLS_DC) index = NULL; } } - - *s = '\0'; + *s++='\0'; } @@ -611,7 +610,7 @@ static char *substring_conf(char *start, int len, char quote TSRMLS_DC) } } - *resp = '\0'; + *resp++ = '\0'; return result; } @@ -789,6 +788,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) int str_len = 0, num_vars = 0, num_vars_max = 2*10, *len_list = NULL; char **val_list = NULL; #endif + zend_bool magic_quotes_gpc; multipart_buffer *mbuff; zval *array_ptr = (zval *) arg; int fd=-1; @@ -925,7 +925,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) if (sapi_module.input_filter(PARSE_POST, param, &value, value_len, &new_val_len TSRMLS_CC)) { if (php_rfc1867_callback != NULL) { multipart_event_formdata event_formdata; - size_t newlength = new_val_len; + size_t newlength = 0; event_formdata.post_bytes_processed = SG(read_post_bytes); event_formdata.name = param; @@ -1077,12 +1077,12 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) } - if (PG(upload_max_filesize) > 0 && (total_bytes+blen) > PG(upload_max_filesize)) { + if (PG(upload_max_filesize) > 0 && total_bytes > PG(upload_max_filesize)) { #if DEBUG_FILE_UPLOAD sapi_module.sapi_error(E_NOTICE, "upload_max_filesize of %ld bytes exceeded - file [%s=%s] not saved", PG(upload_max_filesize), param, filename); #endif cancel_upload = UPLOAD_ERROR_A; - } else if (max_file_size && ((total_bytes+blen) > max_file_size)) { + } else if (max_file_size && (total_bytes > max_file_size)) { #if DEBUG_FILE_UPLOAD sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of %ld bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename); #endif @@ -1279,30 +1279,26 @@ filedone: } s = ""; - { - /* store temp_filename as-is (without magic_quotes_gpc-ing it, in case upload_tmp_dir - * contains escapeable characters. escape only the variable name.) */ - zval zfilename; - - /* Initialize variables */ - add_protected_variable(param TSRMLS_CC); + /* Initialize variables */ + add_protected_variable(param TSRMLS_CC); - /* if param is of form xxx[.*] this will cut it to xxx */ - if (!is_anonymous) { - ZVAL_STRING(&zfilename, temp_filename, 1); - safe_php_register_variable_ex(param, &zfilename, NULL, 1 TSRMLS_CC); - } - - /* Add $foo[tmp_name] */ - if (is_arr_upload) { - snprintf(lbuf, llen, "%s[tmp_name][%s]", abuf, array_index); - } else { - snprintf(lbuf, llen, "%s[tmp_name]", param); - } - add_protected_variable(lbuf TSRMLS_CC); - ZVAL_STRING(&zfilename, temp_filename, 1); - register_http_post_files_variable_ex(lbuf, &zfilename, http_post_files, 1 TSRMLS_CC); + magic_quotes_gpc = PG(magic_quotes_gpc); + PG(magic_quotes_gpc) = 0; + /* if param is of form xxx[.*] this will cut it to xxx */ + if (!is_anonymous) { + safe_php_register_variable(param, temp_filename, strlen(temp_filename), NULL, 1 TSRMLS_CC); } + + /* Add $foo[tmp_name] */ + if (is_arr_upload) { + snprintf(lbuf, llen, "%s[tmp_name][%s]", abuf, array_index); + } else { + snprintf(lbuf, llen, "%s[tmp_name]", param); + } + add_protected_variable(lbuf TSRMLS_CC); + register_http_post_files_variable(lbuf, temp_filename, http_post_files, 1 TSRMLS_CC); + + PG(magic_quotes_gpc) = magic_quotes_gpc; { zval file_size, error_type; diff --git a/main/snprintf.c b/main/snprintf.c index ac53a89303..dc07f19437 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -155,7 +155,10 @@ PHPAPI char *php_gcvt(double value, int ndigit, char dec_point, char exponent, c *dst++ = '-'; } - if ((decpt >= 0 && decpt > ndigit) || decpt < -3) { /* use E-style */ + for (i = 0; i < ndigit && digits[i] != '\0'; i++); + + if ((decpt >= 0 && decpt - i > 4) + || (decpt < 0 && decpt < -3)) { /* use E-style */ /* exponential format (e.g. 1.2345e+13) */ if (--decpt < 0) { sign = 1; @@ -1268,42 +1271,6 @@ PHPAPI int ap_php_vsnprintf(char *buf, size_t len, const char *format, va_list a } /* }}} */ -PHPAPI int ap_php_vasprintf(char **buf, const char *format, va_list ap) /* {{{ */ -{ - va_list ap2; - int cc; - - va_copy(ap2, ap); - cc = ap_php_vsnprintf(NULL, 0, format, ap2); - va_end(ap2); - - *buf = NULL; - - if (cc >= 0) { - if ((*buf = malloc(++cc)) != NULL) { - if ((cc = ap_php_vsnprintf(*buf, cc, format, ap)) < 0) { - free(*buf); - *buf = NULL; - } - } - } - - return cc; -} -/* }}} */ - -PHPAPI int ap_php_asprintf(char **buf, const char *format, ...) /* {{{ */ -{ - int cc; - va_list ap; - - va_start(ap, format); - cc = vasprintf(buf, format, ap); - va_end(ap); - return cc; -} -/* }}} */ - /* * Local variables: * tab-width: 4 diff --git a/main/snprintf.h b/main/snprintf.h index 0b7470874e..3ba50259ff 100644 --- a/main/snprintf.h +++ b/main/snprintf.h @@ -82,8 +82,6 @@ PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...); 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_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 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, @@ -111,14 +109,6 @@ END_EXTERN_C() #endif #define vsnprintf ap_php_vsnprintf -#ifndef HAVE_VASPRINTF -#define vasprintf ap_php_vasprintf -#endif - -#ifndef HAVE_ASPRINTF -#define asprintf ap_php_asprintf -#endif - #ifdef sprintf #undef sprintf #endif diff --git a/main/streams/filter.c b/main/streams/filter.c index ae3605ccdb..d0ea166403 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -381,12 +381,15 @@ PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream stream->writepos = 0; break; case PSFS_PASS_ON: - /* If any data is consumed, we cannot rely upon the existing read buffer, - as the filtered data must replace the existing data, so invalidate the cache */ - /* note that changes here should be reflected in - main/streams/streams.c::php_stream_fill_read_buffer */ - stream->writepos = 0; - stream->readpos = 0; + /* Put any filtered data onto the readbuffer stack. + Previously read data has been at least partially consumed. */ + stream->readpos += consumed; + + if (stream->writepos == stream->readpos) { + /* Entirely consumed */ + stream->writepos = 0; + stream->readpos = 0; + } while (brig_outp->head) { bucket = brig_outp->head; diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 48974d841d..afc4e128e8 100755 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -209,7 +209,7 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *pat int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { glob_s_t *pglob; - int ret; + int ret, path_len; char *tmp, *pos; if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path TSRMLS_CC)) { @@ -218,9 +218,12 @@ static php_stream *php_glob_stream_opener(php_stream_wrapper *wrapper, char *pat if (!strncmp(path, "glob://", sizeof("glob://")-1)) { path += sizeof("glob://")-1; + path_len = strlen(path); if (opened_path) { - *opened_path = estrdup(path); + *opened_path = estrndup(path, path_len); } + } else { + path_len = strlen(path); } pglob = ecalloc(sizeof(*pglob), 1); diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 118acc7647..6be46df215 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -242,7 +242,6 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha #ifdef ESPIPE if (stream->position == (off_t)-1 && errno == ESPIPE) { stream->position = 0; - stream->flags |= PHP_STREAM_FLAG_NO_SEEK; self->is_pipe = 1; } #endif diff --git a/main/streams/streams.c b/main/streams/streams.c index 704e2ccd20..65421c299d 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -448,10 +448,6 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL }; php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap; - /* Invalidate the existing cache, otherwise reads can fail, see note in - main/streams/filter.c::_php_stream_filter_append */ - stream->writepos = stream->readpos = 0; - /* allocate a buffer for reading chunks */ chunk_buf = emalloc(stream->chunk_size); @@ -540,16 +536,16 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D efree(chunk_buf); } else { - /* reduce buffer memory consumption if possible, to avoid a realloc */ - if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) { - memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos); - stream->writepos -= stream->readpos; - stream->readpos = 0; - } /* is there enough data in the buffer ? */ - while (stream->writepos - stream->readpos < (off_t)size) { + if (stream->writepos - stream->readpos < (off_t)size) { size_t justread = 0; - size_t toread; + + /* reduce buffer memory consumption if possible, to avoid a realloc */ + if (stream->readbuf && stream->readbuflen - stream->writepos < stream->chunk_size) { + memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->readbuflen - stream->readpos); + stream->writepos -= stream->readpos; + stream->readpos = 0; + } /* grow the buffer if required * TODO: this can fail for persistent streams */ @@ -559,17 +555,13 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D stream->is_persistent); } - toread = stream->readbuflen - stream->writepos; justread = stream->ops->read(stream, stream->readbuf + stream->writepos, - toread + stream->readbuflen - stream->writepos TSRMLS_CC); if (justread != (size_t)-1) { stream->writepos += justread; } - if (stream->eof || justread != toread) { - break; - } } } } @@ -650,7 +642,7 @@ PHPAPI int _php_stream_eof(php_stream *stream TSRMLS_DC) /* use the configured timeout when checking eof */ if (!stream->eof && PHP_STREAM_OPTION_RETURN_ERR == php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS, - 0, NULL)) { + -1, NULL)) { stream->eof = 1; } @@ -890,9 +882,6 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re } if (!e) { - if (seek_len < maxlen && !stream->eof) { - return NULL; - } toread = maxlen; } else { toread = e - (char *) stream->readbuf - stream->readpos; @@ -1243,7 +1232,7 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen if (maxlen > 0) { ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent); - while ((len < maxlen) && !php_stream_eof(src)) { + while ((len < maxlen) & !php_stream_eof(src)) { ret = php_stream_read(src, ptr, maxlen - len); len += ret; ptr += ret; @@ -1528,7 +1517,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char n++; } - if ((*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || (n == 4 && !memcmp("data:", path, 5)))) { + if ((*p == ':') && (n > 1) && (!strncmp("//", p+1, 2) || !memcmp("data", path, 4))) { protocol = path; } else if (n == 5 && strncasecmp(path, "zlib:", 5) == 0) { /* BC with older php scripts and zlib wrapper */ diff --git a/main/streams/userspace.c b/main/streams/userspace.c index bfef46f520..fbd03f1d56 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -22,10 +22,6 @@ #include "php.h" #include "php_globals.h" #include "ext/standard/file.h" -#include "ext/standard/flock_compat.h" -#ifdef HAVE_SYS_FILE_H -#include <sys/file.h> -#endif static int le_protocols; @@ -86,19 +82,6 @@ PHP_MINIT_FUNCTION(user_streams) REGISTER_LONG_CONSTANT("STREAM_MKDIR_RECURSIVE", PHP_STREAM_MKDIR_RECURSIVE, CONST_CS|CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_IS_URL", PHP_STREAM_IS_URL, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_OPTION_BLOCKING", PHP_STREAM_OPTION_BLOCKING, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_OPTION_READ_TIMEOUT", PHP_STREAM_OPTION_READ_TIMEOUT, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_OPTION_READ_BUFFER", PHP_STREAM_OPTION_READ_BUFFER, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_OPTION_WRITE_BUFFER", PHP_STREAM_OPTION_WRITE_BUFFER, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_BUFFER_NONE", PHP_STREAM_BUFFER_NONE, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_BUFFER_LINE", PHP_STREAM_BUFFER_LINE, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_BUFFER_FULL", PHP_STREAM_BUFFER_FULL, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_CAST_AS_STREAM", PHP_STREAM_AS_STDIO, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_CAST_FOR_SELECT", PHP_STREAM_AS_FD_FOR_SELECT, CONST_CS|CONST_PERSISTENT); - return SUCCESS; } @@ -128,8 +111,6 @@ typedef struct _php_userstream_data php_userstream_data_t; #define USERSTREAM_DIR_REWIND "dir_rewinddir" #define USERSTREAM_DIR_CLOSE "dir_closedir" #define USERSTREAM_LOCK "stream_lock" -#define USERSTREAM_CAST "stream_cast" -#define USERSTREAM_SET_OPTION "stream_set_option" /* {{{ class should have methods like these: @@ -179,33 +160,6 @@ typedef struct _php_userstream_data php_userstream_data_t; return array( just like that returned by fstat() ); } - function stream_cast($castas) - { - if ($castas == STREAM_CAST_FOR_SELECT) { - return $this->underlying_stream; - } - return false; - } - - function stream_set_option($option, $arg1, $arg2) - { - switch($option) { - case STREAM_OPTION_BLOCKING: - $blocking = $arg1; - ... - case STREAM_OPTION_READ_TIMEOUT: - $sec = $arg1; - $usec = $arg2; - ... - case STREAM_OPTION_WRITE_BUFFER: - $mode = $arg1; - $size = $arg2; - ... - default: - return false; - } - } - function url_stat(string $url, int $flags) { return array( just like that returned by stat() ); @@ -299,7 +253,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena fci.function_table = &uwrap->ce->function_table; fci.function_name = NULL; fci.symbol_table = NULL; - fci.object_ptr = us->object; + fci.object_pp = &us->object; fci.retval_ptr_ptr = &retval_ptr; fci.param_count = 0; fci.params = NULL; @@ -309,7 +263,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, char *filena fcc.function_handler = uwrap->ce->constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(us->object); - fcc.object_ptr = us->object; + fcc.object_pp = &us->object; if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name, uwrap->ce->constructor->common.function_name); @@ -928,7 +882,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; int ret = -1; zval *zvalue = NULL; - zval **args[3]; + zval **args[1]; switch (option) { case PHP_STREAM_OPTION_CHECK_LIVENESS: @@ -946,23 +900,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value case PHP_STREAM_OPTION_LOCKING: MAKE_STD_ZVAL(zvalue); - ZVAL_LONG(zvalue, 0); - - if (value & LOCK_NB) { - Z_LVAL_P(zvalue) |= PHP_LOCK_NB; - } - switch(value & ~LOCK_NB) { - case LOCK_SH: - Z_LVAL_P(zvalue) |= PHP_LOCK_SH; - break; - case LOCK_EX: - Z_LVAL_P(zvalue) |= PHP_LOCK_EX; - break; - case LOCK_UN: - Z_LVAL_P(zvalue) |= PHP_LOCK_UN; - break; - } - + ZVAL_LONG(zvalue, value); args[0] = &zvalue; /* TODO wouldblock */ @@ -987,75 +925,6 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value } break; - - case PHP_STREAM_OPTION_READ_BUFFER: - case PHP_STREAM_OPTION_WRITE_BUFFER: - case PHP_STREAM_OPTION_READ_TIMEOUT: - case PHP_STREAM_OPTION_BLOCKING: { - zval *zoption = NULL; - zval *zptrparam = NULL; - - ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1, 0); - - ALLOC_INIT_ZVAL(zoption); - ZVAL_LONG(zoption, option); - - ALLOC_INIT_ZVAL(zvalue); - ALLOC_INIT_ZVAL(zptrparam); - - args[0] = &zoption; - args[1] = &zvalue; - args[2] = &zptrparam; - - switch(option) { - case PHP_STREAM_OPTION_READ_BUFFER: - case PHP_STREAM_OPTION_WRITE_BUFFER: - ZVAL_LONG(zvalue, value); - if (ptrparam) { - ZVAL_LONG(zptrparam, *(long *)ptrparam); - } else { - ZVAL_LONG(zptrparam, BUFSIZ); - } - break; - case PHP_STREAM_OPTION_READ_TIMEOUT: { - struct timeval tv = *(struct timeval*)ptrparam; - ZVAL_LONG(zvalue, tv.tv_sec); - ZVAL_LONG(zptrparam, tv.tv_usec); - break; - } - case PHP_STREAM_OPTION_BLOCKING: - ZVAL_LONG(zvalue, value); - break; - default: - break; - } - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 3, args, 0, NULL TSRMLS_CC); - - do { - if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!", - us->wrapper->classname); - break; - } - if (retval && zend_is_true(retval)) { - ret = PHP_STREAM_OPTION_RETURN_OK; - } - } while (0); - - if (zoption) { - zval_ptr_dtor(&zoption); - } - if (zptrparam) { - zval_ptr_dtor(&zptrparam); - } - - break; - } } /* clean up */ @@ -1462,76 +1331,12 @@ static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int when } -static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr TSRMLS_DC) -{ - php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval func_name; - zval *retval = NULL; - zval *zcastas = NULL; - zval **args[1]; - php_stream * intstream = NULL; - int call_result; - int ret = FAILURE; - - ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1, 0); - - ALLOC_INIT_ZVAL(zcastas); - switch(castas) { - case PHP_STREAM_AS_FD_FOR_SELECT: - ZVAL_LONG(zcastas, PHP_STREAM_AS_FD_FOR_SELECT); - break; - default: - ZVAL_LONG(zcastas, PHP_STREAM_AS_STDIO); - break; - } - args[0] = &zcastas; - - call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 1, args, 0, NULL TSRMLS_CC); - - do { - if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!", - us->wrapper->classname); - break; - } - if (retval == NULL || !zend_is_true(retval)) { - break; - } - php_stream_from_zval_no_verify(intstream, &retval); - if (!intstream) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource", - us->wrapper->classname); - break; - } - if (intstream == stream) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself", - us->wrapper->classname); - intstream = NULL; - break; - } - ret = php_stream_cast(intstream, castas, retptr, 1); - } while (0); - - if (retval) { - zval_ptr_dtor(&retval); - } - if (zcastas) { - zval_ptr_dtor(&zcastas); - } - - return ret; -} - php_stream_ops php_stream_userspace_ops = { php_userstreamop_write, php_userstreamop_read, php_userstreamop_close, php_userstreamop_flush, "user-space", php_userstreamop_seek, - php_userstreamop_cast, + NULL, /* cast */ php_userstreamop_stat, php_userstreamop_set_option, }; diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index a7736878f4..0684d1ae76 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -280,8 +280,12 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void if (sock->socket == -1) { alive = 0; - } else if (php_pollfd_for(sock->socket, PHP_POLLREADABLE|POLLPRI, &tv) > 0) { - if (0 == recv(sock->socket, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EAGAIN) { + } else { + if (php_pollfd_for(sock->socket, PHP_POLLREADABLE|POLLPRI, &tv) > 0) { + if (0 == recv(sock->socket, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EAGAIN) { + alive = 0; + } + } else { alive = 0; } } |