summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/ftp/php_ftp.c4
-rw-r--r--ext/ftp/tests/ftp_nb_continue.phpt182
-rw-r--r--ext/ftp/tests/server.inc7
-rw-r--r--ext/standard/tests/serialize/bug64146.phpt60
-rw-r--r--ext/standard/tests/serialize/bug65806.phpt83
-rw-r--r--ext/standard/var.c6
6 files changed, 337 insertions, 5 deletions
diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c
index da22e0b63e..21e13ea460 100644
--- a/ext/ftp/php_ftp.c
+++ b/ext/ftp/php_ftp.c
@@ -968,7 +968,9 @@ PHP_FUNCTION(ftp_nb_get)
RETURN_LONG(PHP_FTP_FAILED);
}
- php_stream_close(outstream);
+ if (ret == PHP_FTP_FINISHED){
+ php_stream_close(outstream);
+ }
RETURN_LONG(ret);
}
diff --git a/ext/ftp/tests/ftp_nb_continue.phpt b/ext/ftp/tests/ftp_nb_continue.phpt
new file mode 100644
index 0000000000..1f70339913
--- /dev/null
+++ b/ext/ftp/tests/ftp_nb_continue.phpt
@@ -0,0 +1,182 @@
+--TEST--
+Testing whether ftp_nb_continue() fetches more data
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$file = "mediumfile.txt";
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+if (!$ftp) die("Couldn't connect to the server");
+
+$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $file;
+touch($local_file);
+
+$r = ftp_nb_get($ftp, $local_file, $file, FTP_BINARY);
+while ($r == FTP_MOREDATA) {
+ $r = ftp_nb_continue($ftp);
+}
+ftp_close($ftp);
+
+echo file_get_contents($local_file);
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "mediumfile.txt");
+?>
+--EXPECT--
+This is line 0 of the test data.
+This is line 1 of the test data.
+This is line 2 of the test data.
+This is line 3 of the test data.
+This is line 4 of the test data.
+This is line 5 of the test data.
+This is line 6 of the test data.
+This is line 7 of the test data.
+This is line 8 of the test data.
+This is line 9 of the test data.
+This is line 10 of the test data.
+This is line 11 of the test data.
+This is line 12 of the test data.
+This is line 13 of the test data.
+This is line 14 of the test data.
+This is line 15 of the test data.
+This is line 16 of the test data.
+This is line 17 of the test data.
+This is line 18 of the test data.
+This is line 19 of the test data.
+This is line 20 of the test data.
+This is line 21 of the test data.
+This is line 22 of the test data.
+This is line 23 of the test data.
+This is line 24 of the test data.
+This is line 25 of the test data.
+This is line 26 of the test data.
+This is line 27 of the test data.
+This is line 28 of the test data.
+This is line 29 of the test data.
+This is line 30 of the test data.
+This is line 31 of the test data.
+This is line 32 of the test data.
+This is line 33 of the test data.
+This is line 34 of the test data.
+This is line 35 of the test data.
+This is line 36 of the test data.
+This is line 37 of the test data.
+This is line 38 of the test data.
+This is line 39 of the test data.
+This is line 40 of the test data.
+This is line 41 of the test data.
+This is line 42 of the test data.
+This is line 43 of the test data.
+This is line 44 of the test data.
+This is line 45 of the test data.
+This is line 46 of the test data.
+This is line 47 of the test data.
+This is line 48 of the test data.
+This is line 49 of the test data.
+This is line 50 of the test data.
+This is line 51 of the test data.
+This is line 52 of the test data.
+This is line 53 of the test data.
+This is line 54 of the test data.
+This is line 55 of the test data.
+This is line 56 of the test data.
+This is line 57 of the test data.
+This is line 58 of the test data.
+This is line 59 of the test data.
+This is line 60 of the test data.
+This is line 61 of the test data.
+This is line 62 of the test data.
+This is line 63 of the test data.
+This is line 64 of the test data.
+This is line 65 of the test data.
+This is line 66 of the test data.
+This is line 67 of the test data.
+This is line 68 of the test data.
+This is line 69 of the test data.
+This is line 70 of the test data.
+This is line 71 of the test data.
+This is line 72 of the test data.
+This is line 73 of the test data.
+This is line 74 of the test data.
+This is line 75 of the test data.
+This is line 76 of the test data.
+This is line 77 of the test data.
+This is line 78 of the test data.
+This is line 79 of the test data.
+This is line 80 of the test data.
+This is line 81 of the test data.
+This is line 82 of the test data.
+This is line 83 of the test data.
+This is line 84 of the test data.
+This is line 85 of the test data.
+This is line 86 of the test data.
+This is line 87 of the test data.
+This is line 88 of the test data.
+This is line 89 of the test data.
+This is line 90 of the test data.
+This is line 91 of the test data.
+This is line 92 of the test data.
+This is line 93 of the test data.
+This is line 94 of the test data.
+This is line 95 of the test data.
+This is line 96 of the test data.
+This is line 97 of the test data.
+This is line 98 of the test data.
+This is line 99 of the test data.
+This is line 100 of the test data.
+This is line 101 of the test data.
+This is line 102 of the test data.
+This is line 103 of the test data.
+This is line 104 of the test data.
+This is line 105 of the test data.
+This is line 106 of the test data.
+This is line 107 of the test data.
+This is line 108 of the test data.
+This is line 109 of the test data.
+This is line 110 of the test data.
+This is line 111 of the test data.
+This is line 112 of the test data.
+This is line 113 of the test data.
+This is line 114 of the test data.
+This is line 115 of the test data.
+This is line 116 of the test data.
+This is line 117 of the test data.
+This is line 118 of the test data.
+This is line 119 of the test data.
+This is line 120 of the test data.
+This is line 121 of the test data.
+This is line 122 of the test data.
+This is line 123 of the test data.
+This is line 124 of the test data.
+This is line 125 of the test data.
+This is line 126 of the test data.
+This is line 127 of the test data.
+This is line 128 of the test data.
+This is line 129 of the test data.
+This is line 130 of the test data.
+This is line 131 of the test data.
+This is line 132 of the test data.
+This is line 133 of the test data.
+This is line 134 of the test data.
+This is line 135 of the test data.
+This is line 136 of the test data.
+This is line 137 of the test data.
+This is line 138 of the test data.
+This is line 139 of the test data.
+This is line 140 of the test data.
+This is line 141 of the test data.
+This is line 142 of the test data.
+This is line 143 of the test data.
+This is line 144 of the test data.
+This is line 145 of the test data.
+This is line 146 of the test data.
+This is line 147 of the test data.
+This is line 148 of the test data.
+This is line 149 of the test data.
diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc
index 7dc8fa08d9..bb0c1ff10b 100644
--- a/ext/ftp/tests/server.inc
+++ b/ext/ftp/tests/server.inc
@@ -368,6 +368,13 @@ if ($pid) {
}
fputs($s, "226 Closing data Connection.\r\n");
break;
+ case "mediumfile":
+ fputs($s, "150 File status okay; about to open data connection.\r\n");
+ for($i = 0; $i < 150; $i++){
+ fputs($fs, "This is line $i of the test data.\n");
+ }
+ fputs($s, "226 Closing data Connection.\r\n");
+
default:
fputs($s, "550 {$matches[1]}: No such file or directory \r\n");
break;
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..cafb8fa342 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -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 {