summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/array.c37
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/http_fopen_wrapper.c61
-rw-r--r--ext/standard/tests/file/disk_free_space_basic.phpt6
-rw-r--r--ext/standard/tests/general_functions/var_export-locale.phpt8
-rw-r--r--ext/standard/tests/general_functions/var_export_basic3.phpt36
-rw-r--r--ext/standard/tests/general_functions/var_export_basic5.phpt10
-rw-r--r--ext/standard/tests/http/bug61548.phpt118
-rw-r--r--ext/standard/tests/serialize/bug64146.phpt60
-rw-r--r--ext/standard/tests/serialize/bug65806.phpt83
-rw-r--r--ext/standard/var.c8
11 files changed, 352 insertions, 76 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 51972033ee..360a691d38 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2222,13 +2222,14 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS
case HASH_KEY_IS_STRING:
if (recursive && zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == SUCCESS) {
HashTable *thash = Z_TYPE_PP(dest_entry) == IS_ARRAY ? Z_ARRVAL_PP(dest_entry) : NULL;
+ zval *src_zval;
+ zval *tmp = NULL;
if ((thash && thash->nApplyCount > 1) || (*src_entry == *dest_entry && Z_ISREF_PP(dest_entry) && (Z_REFCOUNT_PP(dest_entry) % 2))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
return 0;
}
SEPARATE_ZVAL(dest_entry);
- SEPARATE_ZVAL(src_entry);
if (Z_TYPE_PP(dest_entry) == IS_NULL) {
convert_to_array_ex(dest_entry);
@@ -2236,23 +2237,34 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS
} else {
convert_to_array_ex(dest_entry);
}
- if (Z_TYPE_PP(src_entry) == IS_NULL) {
- convert_to_array_ex(src_entry);
- add_next_index_null(*src_entry);
+ if (Z_TYPE_PP(src_entry) == IS_OBJECT) {
+ ALLOC_ZVAL(src_zval);
+ INIT_PZVAL_COPY(src_zval, *src_entry);
+ zval_copy_ctor(src_zval);
+ convert_to_array(src_zval);
+ tmp = src_zval;
} else {
- convert_to_array_ex(src_entry);
+ src_zval = *src_entry;
}
- if (thash) {
- thash->nApplyCount++;
- }
- if (!php_array_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry), recursive TSRMLS_CC)) {
+ if (Z_TYPE_P(src_zval) == IS_ARRAY) {
+ if (thash) {
+ thash->nApplyCount++;
+ }
+ if (!php_array_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_P(src_zval), recursive TSRMLS_CC)) {
+ if (thash) {
+ thash->nApplyCount--;
+ }
+ return 0;
+ }
if (thash) {
thash->nApplyCount--;
}
- return 0;
+ } else {
+ Z_ADDREF_PP(src_entry);
+ zend_hash_next_index_insert(Z_ARRVAL_PP(dest_entry), &src_zval, sizeof(zval *), NULL);
}
- if (thash) {
- thash->nApplyCount--;
+ if (tmp) {
+ zval_ptr_dtor(&tmp);
}
} else {
Z_ADDREF_PP(src_entry);
@@ -2356,7 +2368,6 @@ static void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETERS, int
array_init_size(return_value, init_size);
for (i = 0; i < argc; i++) {
- SEPARATE_ZVAL(args[i]);
if (!replace) {
php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]), recursive TSRMLS_CC);
} else if (recursive && i > 0) { /* First array will be copied directly instead */
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index eca7d90368..b4128e066b 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -3639,6 +3639,7 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */
BASIC_ADD_SUBMODULE(dl)
BASIC_ADD_SUBMODULE(mail)
+ BASIC_ADD_SUBMODULE(streams)
BASIC_MINIT_SUBMODULE(file)
BASIC_MINIT_SUBMODULE(pack)
BASIC_MINIT_SUBMODULE(browscap)
diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c
index b8676bbba4..4605e7494f 100644
--- a/ext/standard/http_fopen_wrapper.c
+++ b/ext/standard/http_fopen_wrapper.c
@@ -84,6 +84,30 @@
#define HTTP_WRAPPER_HEADER_INIT 1
#define HTTP_WRAPPER_REDIRECTED 2
+static inline void strip_header(char *header_bag, char *lc_header_bag,
+ const char *lc_header_name)
+{
+ char *lc_header_start = strstr(lc_header_bag, lc_header_name);
+ char *header_start = header_bag + (lc_header_start - lc_header_bag);
+
+ if (lc_header_start
+ && (lc_header_start == lc_header_bag || *(lc_header_start-1) == '\n')
+ ) {
+ char *lc_eol = strchr(lc_header_start, '\n');
+ char *eol = header_start + (lc_eol - lc_header_start);
+
+ if (lc_eol) {
+ size_t eollen = strlen(lc_eol);
+
+ memmove(lc_header_start, lc_eol+1, eollen);
+ memmove(header_start, eol+1, eollen);
+ } else {
+ *lc_header_start = '\0';
+ *header_start = '\0';
+ }
+ }
+}
+
php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context, int redirect_max, int flags STREAMS_DC TSRMLS_DC) /* {{{ */
{
php_stream *stream = NULL;
@@ -425,40 +449,17 @@ finish:
if (tmp && strlen(tmp) > 0) {
char *s;
- if (!header_init) { /* Remove post headers for redirects */
- int l = strlen(tmp);
- char *s2, *tmp_c = estrdup(tmp);
-
- php_strtolower(tmp_c, l);
- if ((s = strstr(tmp_c, "content-length:"))) {
- if ((s2 = memchr(s, '\n', tmp_c + l - s))) {
- int b = tmp_c + l - 1 - s2;
- memmove(tmp, tmp + (s2 + 1 - tmp_c), b);
- memmove(tmp_c, s2 + 1, b);
-
- } else {
- tmp[s - tmp_c] = *s = '\0';
- }
- l = strlen(tmp_c);
- }
- if ((s = strstr(tmp_c, "content-type:"))) {
- if ((s2 = memchr(s, '\n', tmp_c + l - s))) {
- memmove(tmp, tmp + (s2 + 1 - tmp_c), tmp_c + l - 1 - s2);
- } else {
- tmp[s - tmp_c] = '\0';
- }
- }
-
- efree(tmp_c);
- tmp_c = php_trim(tmp, strlen(tmp), NULL, 0, NULL, 3 TSRMLS_CC);
- efree(tmp);
- tmp = tmp_c;
- }
-
user_headers = estrdup(tmp);
/* Make lowercase for easy comparison against 'standard' headers */
php_strtolower(tmp, strlen(tmp));
+
+ if (!header_init) {
+ /* strip POST headers on redirect */
+ strip_header(user_headers, tmp, "content-length:");
+ strip_header(user_headers, tmp, "content-type:");
+ }
+
if ((s = strstr(tmp, "user-agent:")) &&
(s == tmp || *(s-1) == '\r' || *(s-1) == '\n' ||
*(s-1) == '\t' || *(s-1) == ' ')) {
diff --git a/ext/standard/tests/file/disk_free_space_basic.phpt b/ext/standard/tests/file/disk_free_space_basic.phpt
index 7ea8d36153..200e92ab43 100644
--- a/ext/standard/tests/file/disk_free_space_basic.phpt
+++ b/ext/standard/tests/file/disk_free_space_basic.phpt
@@ -1,5 +1,9 @@
--TEST--
Test disk_free_space and its alias diskfreespace() functions : basic functionality
+--SKIPIF--
+<?php
+if (getenv("TRAVIS") === "true") die("skip inaccurate on TravisCI");
+?>
--INI--
memory_limit=32M
--FILE--
@@ -33,7 +37,7 @@ echo "\n Free Space after writing to a file\n";
$space2 = disk_free_space($file_path.$dir);
var_dump( $space2 );
-if( $space1 > $space2 )
+if($space1 > $space2 )
echo "\n Free Space Value Is Correct\n";
else
echo "\n Free Space Value Is Incorrect\n";
diff --git a/ext/standard/tests/general_functions/var_export-locale.phpt b/ext/standard/tests/general_functions/var_export-locale.phpt
index 37142cf34c..3cbebe9c72 100644
--- a/ext/standard/tests/general_functions/var_export-locale.phpt
+++ b/ext/standard/tests/general_functions/var_export-locale.phpt
@@ -784,15 +784,15 @@ string(20) "array (
Iteration 13
array (
0 => 10.5,
- 1 => 5.6,
+ 1 => 5.5999999999999996,
)
array (
0 => 10.5,
- 1 => 5.6,
+ 1 => 5.5999999999999996,
)
-string(34) "array (
+string(49) "array (
0 => 10.5,
- 1 => 5.6,
+ 1 => 5.5999999999999996,
)"
diff --git a/ext/standard/tests/general_functions/var_export_basic3.phpt b/ext/standard/tests/general_functions/var_export_basic3.phpt
index 2997215910..9e27d90425 100644
--- a/ext/standard/tests/general_functions/var_export_basic3.phpt
+++ b/ext/standard/tests/general_functions/var_export_basic3.phpt
@@ -96,9 +96,9 @@ string(1) "0"
-- Iteration: -0.1 --
--0.1
--0.1
-string(4) "-0.1"
+-0.10000000000000001
+-0.10000000000000001
+string(20) "-0.10000000000000001"
-- Iteration: 10.0000000000000000005 --
@@ -120,9 +120,9 @@ string(6) "100000"
-- Iteration: 1e-5 --
-1.0E-5
-1.0E-5
-string(6) "1.0E-5"
+1.0000000000000001E-5
+1.0000000000000001E-5
+string(21) "1.0000000000000001E-5"
-- Iteration: 1e+5 --
@@ -144,9 +144,9 @@ string(6) "100000"
-- Iteration: 1E-5 --
-1.0E-5
-1.0E-5
-string(6) "1.0E-5"
+1.0000000000000001E-5
+1.0000000000000001E-5
+string(21) "1.0000000000000001E-5"
-- Iteration: .5e+7 --
@@ -156,20 +156,20 @@ string(7) "5000000"
-- Iteration: .6e-19 --
-6.0E-20
-6.0E-20
-string(7) "6.0E-20"
+6.0000000000000006E-20
+6.0000000000000006E-20
+string(22) "6.0000000000000006E-20"
-- Iteration: .05E+44 --
-5.0E+42
-5.0E+42
-string(7) "5.0E+42"
+5.0000000000000001E+42
+5.0000000000000001E+42
+string(22) "5.0000000000000001E+42"
-- Iteration: .0034E-30 --
-3.4E-33
-3.4E-33
-string(7) "3.4E-33"
+3.4000000000000001E-33
+3.4000000000000001E-33
+string(22) "3.4000000000000001E-33"
===DONE===
diff --git a/ext/standard/tests/general_functions/var_export_basic5.phpt b/ext/standard/tests/general_functions/var_export_basic5.phpt
index 96b3f54cc9..1512fa8377 100644
--- a/ext/standard/tests/general_functions/var_export_basic5.phpt
+++ b/ext/standard/tests/general_functions/var_export_basic5.phpt
@@ -233,15 +233,15 @@ string(20) "array (
--Iteration: array(10.5, 5.6) --
array (
0 => 10.5,
- 1 => 5.6,
+ 1 => 5.5999999999999996,
)
array (
0 => 10.5,
- 1 => 5.6,
+ 1 => 5.5999999999999996,
)
-string(34) "array (
+string(49) "array (
0 => 10.5,
- 1 => 5.6,
+ 1 => 5.5999999999999996,
)"
@@ -274,4 +274,4 @@ string(41) "array (
1 => 'test',
)"
-===DONE=== \ No newline at end of file
+===DONE===
diff --git a/ext/standard/tests/http/bug61548.phpt b/ext/standard/tests/http/bug61548.phpt
new file mode 100644
index 0000000000..138b15a338
--- /dev/null
+++ b/ext/standard/tests/http/bug61548.phpt
@@ -0,0 +1,118 @@
+--TEST--
+Bug #61548 (content-type must appear at the end of headers)
+--INI--
+allow_url_fopen=1
+--SKIPIF--
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
+--FILE--
+<?php
+require 'server.inc';
+
+function do_test($header) {
+ $options = [
+ 'http' => [
+ 'method' => 'POST',
+ 'header' => $header,
+ 'follow_location' => true,
+ ],
+ ];
+
+ $ctx = stream_context_create($options);
+
+ $responses = [
+ "data://text/plain,HTTP/1.1 201\r\nLocation: /foo\r\n\r\n",
+ "data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n",
+ ];
+ $pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
+
+ $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
+ fseek($output, 0, SEEK_SET);
+ echo stream_get_contents($output);
+
+ http_server_kill($pid);
+}
+
+do_test("First:1\nSecond:2\nContent-type: text/plain");
+do_test("First:1\nSecond:2\nContent-type: text/plain\n");
+do_test("First:1\nSecond:2\nContent-type: text/plain\nThird:");
+do_test("First:1\nContent-type:text/plain\nSecond:2");
+do_test("First:1\nContent-type:text/plain\nSecond:2\n");
+do_test("First:1\nContent-type:text/plain\nSecond:2\nThird:");
+
+?>
+Done
+--EXPECT--
+POST / HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+Content-type: text/plain
+
+GET /foo HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+
+
+POST / HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+Content-type: text/plain
+
+GET /foo HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+
+
+POST / HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+Content-type: text/plain
+Third:
+
+GET /foo HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+Third:
+
+POST / HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Content-type:text/plain
+Second:2
+
+GET /foo HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+
+POST / HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Content-type:text/plain
+Second:2
+
+GET /foo HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+
+POST / HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Content-type:text/plain
+Second:2
+Third:
+
+GET /foo HTTP/1.0
+Host: 127.0.0.1:12342
+First:1
+Second:2
+Third:
+
+Done
+
diff --git a/ext/standard/tests/serialize/bug64146.phpt b/ext/standard/tests/serialize/bug64146.phpt
new file mode 100644
index 0000000000..18ae78d0ce
--- /dev/null
+++ b/ext/standard/tests/serialize/bug64146.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Bug #64146 (serialize incorrectly saving objects when they are cloned)
+--FILE--
+<?php
+
+echo "Test\n";
+
+class A
+{
+ public $a = array();
+
+ public function __construct()
+ {
+ $this->a[] = new B(1);
+ $this->a[] = new B(2);
+ }
+}
+
+class B implements Serializable
+{
+ public $b;
+
+ public function __construct($c)
+ {
+ $this->b = new C($c);
+ }
+
+ public function serialize()
+ {
+ return serialize(clone $this->b);
+ }
+
+ public function unserialize($data)
+ {
+ $this->b = unserialize($data);
+ }
+}
+
+class C
+{
+ public $c;
+
+ public function __construct($c)
+ {
+ $this->c = $c;
+ }
+}
+
+$a = unserialize(serialize(new A()));
+
+print $a->a[0]->b->c . "\n";
+print $a->a[1]->b->c . "\n";
+
+?>
+Done
+--EXPECT--
+Test
+1
+2
+Done
diff --git a/ext/standard/tests/serialize/bug65806.phpt b/ext/standard/tests/serialize/bug65806.phpt
new file mode 100644
index 0000000000..19fab95c64
--- /dev/null
+++ b/ext/standard/tests/serialize/bug65806.phpt
@@ -0,0 +1,83 @@
+--TEST--
+Bug #65806 (unserialize fails with object which is referenced multiple times)
+--FILE--
+<?php
+class myObjA {}
+class myObjB {
+ public $attrA;
+ public $attrB;
+}
+class myObjC {
+ public $attrC;
+ public $attrD;
+}
+class myList {
+ private $_serialized;
+ private $_obj;
+
+ public function __construct($obj)
+ {
+ $this->_obj = $obj;
+ $this->_serialized = serialize($this->_obj);
+ }
+ public function get()
+ {
+ return $this->_obj;
+ }
+ public function __sleep()
+ {
+ $this->_serialized = serialize($this->_obj);
+ return array(
+ "\0" . __CLASS__ . "\0_serialized",
+ );
+ }
+ public function __wakeup()
+ {
+ $this->_obj = unserialize($this->_serialized);
+ }
+}
+
+echo "SCRIPT START" . PHP_EOL;
+
+$objA = new myObjA();
+$objB = new myObjB();
+$objC = new myObjC();
+
+$objB->attrA = new ArrayIterator();
+$objB->attrB = $objA;
+
+$objC->attrC = $objB;
+$objC->attrD = $objA;
+
+$list = new myList($objC);
+
+echo 'check ' . check($list->get()) . PHP_EOL;
+
+echo "start serialize/unserialize" . PHP_EOL;
+$newList = unserialize(serialize($list));
+echo "finish serialize/unserialize" . PHP_EOL;
+
+//after unserialize the property myObjC::attrD is null instead of expected object
+echo 'check ' . check($newList->get()) . PHP_EOL;
+
+echo "SCRIPT END" . PHP_EOL ;
+
+function check(myObjC $obj) {
+
+ if (!is_object($obj->attrC)) {
+ return 'failed (myObjC::attrC => ' . var_export($obj->attrC, true) . ')';
+ }
+ if (!is_object($obj->attrD)) {
+ return 'failed (myObjC::attrD => ' . var_export($obj->attrD, true) . ')';
+ }
+ return 'successful';
+}
+?>
+--EXPECT--
+SCRIPT START
+check successful
+start serialize/unserialize
+finish serialize/unserialize
+check successful
+SCRIPT END
+
diff --git a/ext/standard/var.c b/ext/standard/var.c
index cd868bb50f..fb2a310f4c 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -436,7 +436,7 @@ PHPAPI void php_var_export_ex(zval **struc, int level, smart_str *buf TSRMLS_DC)
smart_str_append_long(buf, Z_LVAL_PP(struc));
break;
case IS_DOUBLE:
- tmp_len = spprintf(&tmp_str, 0,"%.*H", (int) EG(precision), Z_DVAL_PP(struc));
+ tmp_len = spprintf(&tmp_str, 0,"%.*H", PG(serialize_precision), Z_DVAL_PP(struc));
smart_str_appendl(buf, tmp_str, tmp_len);
efree(tmp_str);
break;
@@ -549,11 +549,9 @@ static inline int php_add_var_hash(HashTable *var_hash, zval *var, void *var_old
char id[32], *p;
register int len;
- /* relies on "(long)" being a perfect hash function for data pointers,
- * however the actual identity of an object has had to be determined
- * by its object handle since 5.0. */
if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) {
- p = smart_str_print_long(id + sizeof(id) - 1, (long) Z_OBJ_HANDLE_P(var));
+ p = smart_str_print_long(id + sizeof(id) - 1,
+ (long) zend_objects_get_address(var TSRMLS_CC));
*(--p) = 'O';
len = id + sizeof(id) - 1 - p;
} else {