diff options
29 files changed, 145 insertions, 127 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 48c1469701..078ea9098f 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -5488,7 +5488,7 @@ PHP_FUNCTION(set_include_path) return; } - old_value = zend_ini_string("include_path", sizeof("include_path")-1, 0); + old_value = zend_ini_string("include_path", sizeof("include_path") - 1, 0); /* copy to return here, because alter might free it! */ if (old_value) { RETVAL_STRING(old_value); @@ -5496,7 +5496,7 @@ PHP_FUNCTION(set_include_path) RETVAL_FALSE; } - key = STR_INIT("include_path", sizeof("include_path")-1, 0); + key = STR_INIT("include_path", sizeof("include_path") - 1, 0); if (zend_alter_ini_entry_ex(key, new_value, new_value_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == FAILURE) { STR_RELEASE(key); zval_dtor(return_value); @@ -5516,7 +5516,7 @@ PHP_FUNCTION(get_include_path) return; } - str = zend_ini_string("include_path", sizeof("include_path"), 0); + str = zend_ini_string("include_path", sizeof("include_path") - 1, 0); if (str == NULL) { RETURN_FALSE; diff --git a/ext/standard/file.c b/ext/standard/file.c index 9ac5851ae3..60eedc354f 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1118,7 +1118,8 @@ PHPAPI PHP_FUNCTION(fgetss) retval_len = php_strip_tags(retval, actual_len, &stream->fgetss_state, allowed_tags, allowed_tags_len); //??? RETURN_STRINGL(retval, retval_len, 0); - RETURN_STRINGL(retval, retval_len); + RETVAL_STRINGL(retval, retval_len); + efree(retval); } /* }}} */ diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index 8d1d051f4f..856c94a22b 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -418,7 +418,7 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC) currarg = 1; - while (inpos<Z_STRLEN(args[format_offset])) { + while (inpos < Z_STRLEN(args[format_offset])) { int expprec = 0; zval tmp; diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 1e08f6806f..39c0d17bc2 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -440,9 +440,11 @@ PHP_FUNCTION(stream_get_contents) } } - contents = php_stream_copy_to_mem(stream, maxlen, 0); - - RETURN_STR(contents); + if ((contents = php_stream_copy_to_mem(stream, maxlen, 0))) { + RETURN_STR(contents); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -492,6 +494,7 @@ PHP_FUNCTION(stream_get_meta_data) array_init(return_value); if (!ZVAL_IS_UNDEF(&stream->wrapperdata)) { + Z_ADDREF_P(&stream->wrapperdata); add_assoc_zval(return_value, "wrapper_data", &stream->wrapperdata); } if (stream->wrapper) { @@ -779,7 +782,6 @@ PHP_FUNCTION(stream_select) FD_ZERO(&efds); if (r_array != NULL) { - r_array = Z_REFVAL_P(r_array); set_count = stream_array_to_fd_set(r_array, &rfds, &max_fd TSRMLS_CC); if (set_count > max_set_count) max_set_count = set_count; @@ -787,7 +789,6 @@ PHP_FUNCTION(stream_select) } if (w_array != NULL) { - w_array = Z_REFVAL_P(w_array); set_count = stream_array_to_fd_set(w_array, &wfds, &max_fd TSRMLS_CC); if (set_count > max_set_count) max_set_count = set_count; @@ -795,7 +796,6 @@ PHP_FUNCTION(stream_select) } if (e_array != NULL) { - e_array = Z_REFVAL_P(e_array); set_count = stream_array_to_fd_set(e_array, &efds, &max_fd TSRMLS_CC); if (set_count > max_set_count) max_set_count = set_count; @@ -1300,8 +1300,7 @@ PHP_FUNCTION(stream_get_line) int str_len = 0; long max_length; zval *zstream; - char *buf; - size_t buf_size; + zend_string *buf; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|s", &zstream, &max_length, &str, &str_len) == FAILURE) { @@ -1318,9 +1317,8 @@ PHP_FUNCTION(stream_get_line) php_stream_from_zval(stream, zstream); - if ((buf = php_stream_get_record(stream, max_length, &buf_size, str, str_len TSRMLS_CC))) { -//??? RETURN_STRINGL(buf, buf_size, 0); - RETURN_STRINGL(buf, buf_size); + if ((buf = php_stream_get_record(stream, max_length, str, str_len TSRMLS_CC))) { + RETURN_STR(buf); } else { RETURN_FALSE; } diff --git a/ext/standard/tests/file/bug27508.phpt b/ext/standard/tests/file/bug27508.phpt index 7f012bd8f4..188080aa25 100644 --- a/ext/standard/tests/file/bug27508.phpt +++ b/ext/standard/tests/file/bug27508.phpt @@ -72,9 +72,9 @@ fclose($fp); unlink($tn); ?> --EXPECT-- -bool(false) refcount(1) +bool(false) 0 -bool(false) refcount(1) +bool(false) line1 line2 line3 diff --git a/ext/standard/tests/file/fclose_variation1.phpt b/ext/standard/tests/file/fclose_variation1.phpt index 43a6c343d0..ba3631e50d 100644 --- a/ext/standard/tests/file/fclose_variation1.phpt +++ b/ext/standard/tests/file/fclose_variation1.phpt @@ -10,6 +10,6 @@ fclose($s); echo fread($s2, strlen("<?php")); echo "\nDone.\n"; --EXPECTF-- -Warning: fread(): %d is not a valid stream resource in %s on line %d +Warning: fread(): supplied resource is not a valid stream resource in %s on line %d Done. diff --git a/ext/standard/tests/file/feof_basic.phpt b/ext/standard/tests/file/feof_basic.phpt index ff1d179f6f..78774e58e9 100644 --- a/ext/standard/tests/file/feof_basic.phpt +++ b/ext/standard/tests/file/feof_basic.phpt @@ -97,5 +97,5 @@ bool(false) bool(false) *** closing file, testing eof *** -Warning: feof(): %d is not a valid stream resource in %s on line %d +Warning: feof(): supplied resource is not a valid stream resource in %s on line %d Done diff --git a/ext/standard/tests/file/fgetc_variation2.phpt b/ext/standard/tests/file/fgetc_variation2.phpt index 380c1aa268..169f00ac2c 100644 --- a/ext/standard/tests/file/fgetc_variation2.phpt +++ b/ext/standard/tests/file/fgetc_variation2.phpt @@ -41,7 +41,7 @@ echo "Done"; *** Testing fgetc() : usage variations *** -- Testing fgetc() with closed handle -- -Warning: fgetc(): %d is not a valid stream resource in %s on line %d +Warning: fgetc(): supplied resource is not a valid stream resource in %s on line %d bool(false) -- Testing fgetc() with unset handle -- diff --git a/ext/standard/tests/file/fgets_error.phpt b/ext/standard/tests/file/fgets_error.phpt index 51ae3c6a37..5ab32820ca 100644 --- a/ext/standard/tests/file/fgets_error.phpt +++ b/ext/standard/tests/file/fgets_error.phpt @@ -99,7 +99,7 @@ bool(false) Warning: fgets() expects parameter 1 to be resource, object given in %s on line %d bool(false) -- Testing fgets() with closed/unset file handle -- -Warning: fgets(): %d is not a valid stream resource in %s on line %d +Warning: fgets(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: fgets() expects parameter 1 to be resource, null given in %s on line %d diff --git a/ext/standard/tests/file/fgets_variation2.phpt b/ext/standard/tests/file/fgets_variation2.phpt index 964216bf8c..201755b69c 100644 --- a/ext/standard/tests/file/fgets_variation2.phpt +++ b/ext/standard/tests/file/fgets_variation2.phpt @@ -43,10 +43,10 @@ echo "Done"; *** Testing fgets() : usage variations *** -- Testing fgets() with closed handle -- -Warning: fgets(): %d is not a valid stream resource in %s on line %d +Warning: fgets(): supplied resource is not a valid stream resource in %s on line %d bool(false) -Warning: fgets(): %d is not a valid stream resource in %s on line %d +Warning: fgets(): supplied resource is not a valid stream resource in %s on line %d bool(false) -- Testing fgets() with unset handle -- diff --git a/ext/standard/tests/file/fgetss.phpt b/ext/standard/tests/file/fgetss.phpt index b4ac21167b..2e2bb6b71c 100644 --- a/ext/standard/tests/file/fgetss.phpt +++ b/ext/standard/tests/file/fgetss.phpt @@ -78,6 +78,6 @@ bool(false) Warning: fgetss(): Length parameter must be greater than 0 in %s on line %d bool(false) -Warning: fgetss(): %d is not a valid stream resource in %s on line %d +Warning: fgetss(): supplied resource is not a valid stream resource in %s on line %d bool(false) Done diff --git a/ext/standard/tests/file/fgetss_error.phpt b/ext/standard/tests/file/fgetss_error.phpt index 2b4ad68125..1671662584 100644 --- a/ext/standard/tests/file/fgetss_error.phpt +++ b/ext/standard/tests/file/fgetss_error.phpt @@ -98,7 +98,7 @@ bool(false) Warning: fgetss() expects parameter 1 to be resource, object given in %s on line %d bool(false) -- Testing fgetss() with closed/unset file handle -- -Warning: fgetss(): %d is not a valid stream resource in %s on line %d +Warning: fgetss(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: fgetss() expects parameter 1 to be resource, null given in %s on line %d diff --git a/ext/standard/tests/file/flock.phpt b/ext/standard/tests/file/flock.phpt index efc059cff5..55aae4ab5a 100644 --- a/ext/standard/tests/file/flock.phpt +++ b/ext/standard/tests/file/flock.phpt @@ -43,7 +43,7 @@ NULL Warning: flock() expects parameter 1 to be resource, string given in %s on line %d NULL -Warning: flock(): %d is not a valid stream resource in %s on line %d +Warning: flock(): supplied resource is not a valid stream resource in %s on line %d bool(false) bool(true) bool(true) diff --git a/ext/standard/tests/file/flock_error.phpt b/ext/standard/tests/file/flock_error.phpt index fe61e2a173..4fa1094967 100644 --- a/ext/standard/tests/file/flock_error.phpt +++ b/ext/standard/tests/file/flock_error.phpt @@ -94,7 +94,7 @@ NULL Warning: flock() expects parameter 2 to be long, string given in %s on line %d NULL -Warning: flock(): %d is not a valid stream resource in %s on line %d +Warning: flock(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: flock() expects parameter 1 to be resource, string given in %s on line %d diff --git a/ext/standard/tests/file/fread_error.phpt b/ext/standard/tests/file/fread_error.phpt index 45a5ad1aa9..16c828ec51 100644 --- a/ext/standard/tests/file/fread_error.phpt +++ b/ext/standard/tests/file/fread_error.phpt @@ -103,7 +103,7 @@ bool(false) Notice: Undefined variable: file_content_type in %s on line %d -Warning: fread(): %d is not a valid stream resource in %s on line %d +Warning: fread(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: fread() expects parameter 1 to be resource, null given in %s on line %d diff --git a/ext/standard/tests/file/fscanf_error.phpt b/ext/standard/tests/file/fscanf_error.phpt index 85c0ac4bf6..f93d1b2a57 100644 --- a/ext/standard/tests/file/fscanf_error.phpt +++ b/ext/standard/tests/file/fscanf_error.phpt @@ -70,7 +70,7 @@ NULL Warning: fscanf() expects at least 2 parameters, 1 given in %s on line %d NULL -Warning: fscanf(): %d is not a valid File-Handle resource in %s on line %d +Warning: fscanf(): supplied resource is not a valid File-Handle resource in %s on line %d bool(false) Warning: fscanf(): Different numbers of variable names and field specifiers in %s on line %d diff --git a/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt b/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt index 1779383044..d955340581 100644 --- a/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt +++ b/ext/standard/tests/file/fseek_ftell_rewind_error1.phpt @@ -91,7 +91,7 @@ bool(false) Warning: fseek() expects parameter 1 to be resource, object given in %s on line %d bool(false) -- Testing fseek() with closed/unset file handle -- -Warning: fseek(): %d is not a valid stream resource in %s on line %d +Warning: fseek(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: fseek() expects parameter 1 to be resource, null given in %s on line %d diff --git a/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt b/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt index 1f28abc99c..d297d6c7cb 100644 --- a/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt +++ b/ext/standard/tests/file/fseek_ftell_rewind_error2.phpt @@ -87,7 +87,7 @@ bool(false) Warning: ftell() expects parameter 1 to be resource, object given in %s on line %d bool(false) -- Testing ftell with closed/unset file handle -- -Warning: ftell(): %d is not a valid stream resource in %s on line %d +Warning: ftell(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: ftell() expects parameter 1 to be resource, null given in %s on line %d diff --git a/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt b/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt index 3c928e6465..16a4a0f9dd 100644 --- a/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt +++ b/ext/standard/tests/file/fseek_ftell_rewind_error3.phpt @@ -87,7 +87,7 @@ bool(false) Warning: rewind() expects parameter 1 to be resource, object given in %s on line %d bool(false) -- Testing rewind() with closed/unset file handle -- -Warning: rewind(): %d is not a valid stream resource in %s on line %d +Warning: rewind(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: rewind() expects parameter 1 to be resource, null given in %s on line %d diff --git a/ext/standard/tests/file/fstat.phpt b/ext/standard/tests/file/fstat.phpt index e1ae3e20bc..96924af077 100644 --- a/ext/standard/tests/file/fstat.phpt +++ b/ext/standard/tests/file/fstat.phpt @@ -69,6 +69,6 @@ array(26) { int(%i) } -Warning: fstat(): %d is not a valid stream resource in %s on line %d +Warning: fstat(): supplied resource is not a valid stream resource in %s on line %d bool(false) Done diff --git a/ext/standard/tests/file/ftruncate_error.phpt b/ext/standard/tests/file/ftruncate_error.phpt index 254ad7688d..4823a7739b 100644 --- a/ext/standard/tests/file/ftruncate_error.phpt +++ b/ext/standard/tests/file/ftruncate_error.phpt @@ -114,7 +114,7 @@ Warning: ftruncate() expects parameter 1 to be resource, object given in %s on l bool(false) -- Testing ftruncate() with closed/unset file handle -- -Warning: ftruncate(): %d is not a valid stream resource in %s on line %d +Warning: ftruncate(): supplied resource is not a valid stream resource in %s on line %d bool(false) int(36) diff --git a/ext/standard/tests/file/fwrite_error.phpt b/ext/standard/tests/file/fwrite_error.phpt index 988d618c66..2b28429362 100644 --- a/ext/standard/tests/file/fwrite_error.phpt +++ b/ext/standard/tests/file/fwrite_error.phpt @@ -112,7 +112,7 @@ Warning: fwrite() expects parameter 1 to be resource, object given in %s on line bool(false) -- Testing fwrite() with closed/unset file handle -- -Warning: fwrite(): %d is not a valid stream resource in %s on line %d +Warning: fwrite(): supplied resource is not a valid stream resource in %s on line %d bool(false) Warning: fwrite() expects parameter 1 to be resource, null given in %s on line %d diff --git a/ext/standard/var.c b/ext/standard/var.c index 20bbf545d5..c84c6515f0 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -426,86 +426,91 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf TSRMLS_DC) zend_string *class_name; zend_string *ztmp, *ztmp2; +again: switch (Z_TYPE_P(struc)) { - case IS_BOOL: - if (Z_LVAL_P(struc)) { - smart_str_appendl(buf, "true", 4); - } else { - smart_str_appendl(buf, "false", 5); - } - break; - case IS_NULL: - smart_str_appendl(buf, "NULL", 4); - break; - case IS_LONG: - smart_str_append_long(buf, Z_LVAL_P(struc)); - break; - case IS_DOUBLE: - tmp_len = spprintf(&tmp_str, 0,"%.*H", PG(serialize_precision), Z_DVAL_P(struc)); - smart_str_appendl(buf, tmp_str, tmp_len); - efree(tmp_str); - break; - case IS_STRING: - ztmp = php_addcslashes(Z_STRVAL_P(struc), Z_STRLEN_P(struc), 0, "'\\", 2 TSRMLS_CC); - ztmp2 = php_str_to_str_ex(ztmp->val, ztmp->len, "\0", 1, "' . \"\\0\" . '", 12, 0, NULL); - - smart_str_appendc(buf, '\''); - smart_str_appendl(buf, ztmp2->val, ztmp2->len); - smart_str_appendc(buf, '\''); - - STR_FREE(ztmp); - STR_FREE(ztmp2); - break; - case IS_ARRAY: - myht = Z_ARRVAL_P(struc); - if (myht->nApplyCount > 0){ + case IS_BOOL: + if (Z_LVAL_P(struc)) { + smart_str_appendl(buf, "true", 4); + } else { + smart_str_appendl(buf, "false", 5); + } + break; + case IS_NULL: smart_str_appendl(buf, "NULL", 4); - zend_error(E_WARNING, "var_export does not handle circular references"); - return; - } - if (level > 1) { - smart_str_appendc(buf, '\n'); - buffer_append_spaces(buf, level - 1); - } - smart_str_appendl(buf, "array (\n", 8); - zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_array_element_export, 2, level, buf); + break; + case IS_LONG: + smart_str_append_long(buf, Z_LVAL_P(struc)); + break; + case IS_DOUBLE: + tmp_len = spprintf(&tmp_str, 0,"%.*H", PG(serialize_precision), Z_DVAL_P(struc)); + smart_str_appendl(buf, tmp_str, tmp_len); + efree(tmp_str); + break; + case IS_STRING: + ztmp = php_addcslashes(Z_STRVAL_P(struc), Z_STRLEN_P(struc), 0, "'\\", 2 TSRMLS_CC); + ztmp2 = php_str_to_str_ex(ztmp->val, ztmp->len, "\0", 1, "' . \"\\0\" . '", 12, 0, NULL); + + smart_str_appendc(buf, '\''); + smart_str_appendl(buf, ztmp2->val, ztmp2->len); + smart_str_appendc(buf, '\''); + + STR_FREE(ztmp); + STR_FREE(ztmp2); + break; + case IS_ARRAY: + myht = Z_ARRVAL_P(struc); + if (myht->nApplyCount > 0){ + smart_str_appendl(buf, "NULL", 4); + zend_error(E_WARNING, "var_export does not handle circular references"); + return; + } + if (level > 1) { + smart_str_appendc(buf, '\n'); + buffer_append_spaces(buf, level - 1); + } + smart_str_appendl(buf, "array (\n", 8); + zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_array_element_export, 2, level, buf); - if (level > 1) { - buffer_append_spaces(buf, level - 1); - } - smart_str_appendc(buf, ')'); - - break; + if (level > 1) { + buffer_append_spaces(buf, level - 1); + } + smart_str_appendc(buf, ')'); + + break; - case IS_OBJECT: - myht = Z_OBJPROP_P(struc); - if(myht && myht->nApplyCount > 0){ - smart_str_appendl(buf, "NULL", 4); - zend_error(E_WARNING, "var_export does not handle circular references"); - return; - } - if (level > 1) { - smart_str_appendc(buf, '\n'); - buffer_append_spaces(buf, level - 1); - } - class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(struc, 0 TSRMLS_CC); + case IS_OBJECT: + myht = Z_OBJPROP_P(struc); + if(myht && myht->nApplyCount > 0){ + smart_str_appendl(buf, "NULL", 4); + zend_error(E_WARNING, "var_export does not handle circular references"); + return; + } + if (level > 1) { + smart_str_appendc(buf, '\n'); + buffer_append_spaces(buf, level - 1); + } + class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(struc, 0 TSRMLS_CC); - smart_str_appendl(buf, class_name->val, class_name->len); - smart_str_appendl(buf, "::__set_state(array(\n", 21); + smart_str_appendl(buf, class_name->val, class_name->len); + smart_str_appendl(buf, "::__set_state(array(\n", 21); - STR_RELEASE(class_name); - if (myht) { - zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_object_element_export, 1, level, buf); - } - if (level > 1) { - buffer_append_spaces(buf, level - 1); - } - smart_str_appendl(buf, "))", 2); + STR_RELEASE(class_name); + if (myht) { + zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_object_element_export, 1, level, buf); + } + if (level > 1) { + buffer_append_spaces(buf, level - 1); + } + smart_str_appendl(buf, "))", 2); - break; - default: - smart_str_appendl(buf, "NULL", 4); - break; + break; + case IS_REFERENCE: + struc = Z_REFVAL_P(struc); + goto again; + break; + default: + smart_str_appendl(buf, "NULL", 4); + break; } } /* }}} */ diff --git a/main/php_streams.h b/main/php_streams.h index 39a4a961e7..7e9b6a6c26 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -322,7 +322,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, #define php_stream_gets(stream, buf, maxlen) _php_stream_get_line((stream), (buf), (maxlen), NULL TSRMLS_CC) #define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC) -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC); +PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len TSRMLS_DC); /* CAREFUL! this is equivalent to puts NOT fputs! */ PHPAPI int _php_stream_puts(php_stream *stream, const char *buf TSRMLS_DC); diff --git a/main/php_variables.c b/main/php_variables.c index d8277d267a..671d8e59ff 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -183,7 +183,7 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars if ((gpc_element_p = zend_symtable_str_find(symtable1, index, index_len)) == NULL || Z_TYPE_P(gpc_element_p) != IS_ARRAY) { array_init(&gpc_element); - gpc_element_p = zend_symtable_str_update(symtable1, index, index_len + 1, &gpc_element); + gpc_element_p = zend_symtable_str_update(symtable1, index, index_len, &gpc_element); } } symtable1 = Z_ARRVAL_P(gpc_element_p); diff --git a/main/rfc1867.c b/main/rfc1867.c index 90e823d86c..5acebd5b5b 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -188,16 +188,23 @@ static void register_http_post_files_variable_ex(char *var, zval *val, zval *htt } /* }}} */ -static int unlink_filename(char **filename TSRMLS_DC) /* {{{ */ +static int unlink_filename(zval *el TSRMLS_DC) /* {{{ */ { - VCWD_UNLINK(*filename); + char *filename = (char*)Z_PTR_P(el); + VCWD_UNLINK(filename); return 0; } /* }}} */ + +static void free_filename(zval *el) { + char *filename = (char*)Z_PTR_P(el); + efree(filename); +} + void destroy_uploaded_files_hash(TSRMLS_D) /* {{{ */ { - zend_hash_apply(SG(rfc1867_uploaded_files), (apply_func_t) unlink_filename TSRMLS_CC); + zend_hash_apply(SG(rfc1867_uploaded_files), unlink_filename TSRMLS_CC); zend_hash_destroy(SG(rfc1867_uploaded_files)); FREE_HASHTABLE(SG(rfc1867_uploaded_files)); } @@ -758,7 +765,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */ zend_hash_init(&PG(rfc1867_protected_variables), 5, NULL, NULL, 0); ALLOC_HASHTABLE(uploaded_files); - zend_hash_init(uploaded_files, 5, NULL, free_string_zval, 0); + zend_hash_init(uploaded_files, 5, NULL, free_filename, 0); SG(rfc1867_uploaded_files) = uploaded_files; array_init(&PG(http_globals)[TRACK_VARS_FILES]); diff --git a/main/streams/memory.c b/main/streams/memory.c index b13d8b62ac..e11a109bcb 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -20,9 +20,9 @@ #define _GNU_SOURCE #include "php.h" +#include "ext/standard/base64.h" PHPAPI int php_url_decode(char *str, int len); -PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length); /* Memory streams use a dynamic memory buffer to emulate a stream. * You can use php_stream_memory_open to create a readonly stream @@ -607,6 +607,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con off_t newoffs; zval meta; int base64 = 0, ilen; + zend_string *base64_comma = NULL; ZVAL_NULL(&meta); if (memcmp(path, "data:", 5)) { @@ -674,7 +675,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con plen = sep - path; vlen = (semi ? semi - sep : mlen - plen) - 1 /* '=' */; key = estrndup(path, plen); - add_assoc_stringl_ex(&meta, key, plen + 1, sep + 1, vlen, 1); + add_assoc_stringl_ex(&meta, key, plen, sep + 1, vlen, 1); efree(key); plen += vlen + 1; mlen -= plen; @@ -695,12 +696,14 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con dlen--; if (base64) { - comma = (char*)php_base64_decode((const unsigned char *)comma, dlen, &ilen); - if (!comma) { + base64_comma = php_base64_decode((const unsigned char *)comma, dlen); + if (!base64_comma) { zval_ptr_dtor(&meta); php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "rfc2397: unable to decode"); return NULL; } + comma = base64_comma->val; + ilen = base64_comma->len; } else { comma = estrndup(comma, dlen); ilen = dlen = php_url_decode(comma, dlen); @@ -723,7 +726,11 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con ts->mode = mode && mode[0] == 'r' && mode[1] != '+' ? TEMP_STREAM_READONLY : 0; ZVAL_COPY_VALUE(&ts->meta, &meta); } - efree(comma); + if (base64_comma) { + STR_FREE(base64_comma); + } else { + efree(comma); + } return stream; } diff --git a/main/streams/streams.c b/main/streams/streams.c index c375b672b9..9dde1cfe19 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1015,13 +1015,13 @@ static const char *_php_stream_search_delim(php_stream *stream, } } -PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, const char *delim, size_t delim_len TSRMLS_DC) +PHPAPI zend_string *php_stream_get_record(php_stream *stream, size_t maxlen, const char *delim, size_t delim_len TSRMLS_DC) { - char *ret_buf; /* returned buffer */ + zend_string *ret_buf; /* returned buffer */ const char *found_delim = NULL; size_t buffered_len, tent_ret_len; /* tentative returned length */ - int has_delim = delim_len > 0; + int has_delim = delim_len > 0; if (maxlen == 0) { return NULL; @@ -1090,16 +1090,16 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re } } - ret_buf = emalloc(tent_ret_len + 1); + ret_buf = STR_ALLOC(tent_ret_len, 0); /* php_stream_read will not call ops->read here because the necessary * data is guaranteedly buffered */ - *returned_len = php_stream_read(stream, ret_buf, tent_ret_len); + ret_buf->len = php_stream_read(stream, ret_buf->val, tent_ret_len); if (found_delim) { stream->readpos += delim_len; stream->position += delim_len; } - ret_buf[*returned_len] = '\0'; + ret_buf->val[ret_buf->len] = '\0'; return ret_buf; } diff --git a/main/streams/userspace.c b/main/streams/userspace.c index d193650dbe..58fe5e1e65 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -1510,7 +1510,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T us->wrapper->classname); break; } - if (Z_TYPE(retval) != IS_UNDEF || !zend_is_true(&retval TSRMLS_CC)) { + if (ZVAL_IS_UNDEF(&retval) || !zend_is_true(&retval TSRMLS_CC)) { break; } php_stream_from_zval_no_verify(intstream, &retval); |
