Skip to content

Commit fb6f5d2

Browse files
committed
Merge branch 'PHP-5.5' of https://git.php.net/repository/php-src into PHP-5.5
* 'PHP-5.5' of https://git.php.net/repository/php-src: Fix bug #65667: ftp_nb_continue produces segfault fix bug #64146 (serialize incorrectly saving objects when they are cloned) such a weird hack probably helps in finding regressions in the future
2 parents 366491c + 90f0a77 commit fb6f5d2

File tree

6 files changed

+337
-5
lines changed

6 files changed

+337
-5
lines changed

ext/ftp/php_ftp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,9 @@ PHP_FUNCTION(ftp_nb_get)
968968
RETURN_LONG(PHP_FTP_FAILED);
969969
}
970970

971-
php_stream_close(outstream);
971+
if (ret == PHP_FTP_FINISHED){
972+
php_stream_close(outstream);
973+
}
972974

973975
RETURN_LONG(ret);
974976
}

ext/ftp/tests/ftp_nb_continue.phpt

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
--TEST--
2+
Testing whether ftp_nb_continue() fetches more data
3+
--SKIPIF--
4+
<?php
5+
require 'skipif.inc';
6+
?>
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
$file = "mediumfile.txt";
12+
13+
$ftp = ftp_connect('127.0.0.1', $port);
14+
ftp_login($ftp, 'user', 'pass');
15+
if (!$ftp) die("Couldn't connect to the server");
16+
17+
$local_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . $file;
18+
touch($local_file);
19+
20+
$r = ftp_nb_get($ftp, $local_file, $file, FTP_BINARY);
21+
while ($r == FTP_MOREDATA) {
22+
$r = ftp_nb_continue($ftp);
23+
}
24+
ftp_close($ftp);
25+
26+
echo file_get_contents($local_file);
27+
?>
28+
--CLEAN--
29+
<?php
30+
@unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "mediumfile.txt");
31+
?>
32+
--EXPECT--
33+
This is line 0 of the test data.
34+
This is line 1 of the test data.
35+
This is line 2 of the test data.
36+
This is line 3 of the test data.
37+
This is line 4 of the test data.
38+
This is line 5 of the test data.
39+
This is line 6 of the test data.
40+
This is line 7 of the test data.
41+
This is line 8 of the test data.
42+
This is line 9 of the test data.
43+
This is line 10 of the test data.
44+
This is line 11 of the test data.
45+
This is line 12 of the test data.
46+
This is line 13 of the test data.
47+
This is line 14 of the test data.
48+
This is line 15 of the test data.
49+
This is line 16 of the test data.
50+
This is line 17 of the test data.
51+
This is line 18 of the test data.
52+
This is line 19 of the test data.
53+
This is line 20 of the test data.
54+
This is line 21 of the test data.
55+
This is line 22 of the test data.
56+
This is line 23 of the test data.
57+
This is line 24 of the test data.
58+
This is line 25 of the test data.
59+
This is line 26 of the test data.
60+
This is line 27 of the test data.
61+
This is line 28 of the test data.
62+
This is line 29 of the test data.
63+
This is line 30 of the test data.
64+
This is line 31 of the test data.
65+
This is line 32 of the test data.
66+
This is line 33 of the test data.
67+
This is line 34 of the test data.
68+
This is line 35 of the test data.
69+
This is line 36 of the test data.
70+
This is line 37 of the test data.
71+
This is line 38 of the test data.
72+
This is line 39 of the test data.
73+
This is line 40 of the test data.
74+
This is line 41 of the test data.
75+
This is line 42 of the test data.
76+
This is line 43 of the test data.
77+
This is line 44 of the test data.
78+
This is line 45 of the test data.
79+
This is line 46 of the test data.
80+
This is line 47 of the test data.
81+
This is line 48 of the test data.
82+
This is line 49 of the test data.
83+
This is line 50 of the test data.
84+
This is line 51 of the test data.
85+
This is line 52 of the test data.
86+
This is line 53 of the test data.
87+
This is line 54 of the test data.
88+
This is line 55 of the test data.
89+
This is line 56 of the test data.
90+
This is line 57 of the test data.
91+
This is line 58 of the test data.
92+
This is line 59 of the test data.
93+
This is line 60 of the test data.
94+
This is line 61 of the test data.
95+
This is line 62 of the test data.
96+
This is line 63 of the test data.
97+
This is line 64 of the test data.
98+
This is line 65 of the test data.
99+
This is line 66 of the test data.
100+
This is line 67 of the test data.
101+
This is line 68 of the test data.
102+
This is line 69 of the test data.
103+
This is line 70 of the test data.
104+
This is line 71 of the test data.
105+
This is line 72 of the test data.
106+
This is line 73 of the test data.
107+
This is line 74 of the test data.
108+
This is line 75 of the test data.
109+
This is line 76 of the test data.
110+
This is line 77 of the test data.
111+
This is line 78 of the test data.
112+
This is line 79 of the test data.
113+
This is line 80 of the test data.
114+
This is line 81 of the test data.
115+
This is line 82 of the test data.
116+
This is line 83 of the test data.
117+
This is line 84 of the test data.
118+
This is line 85 of the test data.
119+
This is line 86 of the test data.
120+
This is line 87 of the test data.
121+
This is line 88 of the test data.
122+
This is line 89 of the test data.
123+
This is line 90 of the test data.
124+
This is line 91 of the test data.
125+
This is line 92 of the test data.
126+
This is line 93 of the test data.
127+
This is line 94 of the test data.
128+
This is line 95 of the test data.
129+
This is line 96 of the test data.
130+
This is line 97 of the test data.
131+
This is line 98 of the test data.
132+
This is line 99 of the test data.
133+
This is line 100 of the test data.
134+
This is line 101 of the test data.
135+
This is line 102 of the test data.
136+
This is line 103 of the test data.
137+
This is line 104 of the test data.
138+
This is line 105 of the test data.
139+
This is line 106 of the test data.
140+
This is line 107 of the test data.
141+
This is line 108 of the test data.
142+
This is line 109 of the test data.
143+
This is line 110 of the test data.
144+
This is line 111 of the test data.
145+
This is line 112 of the test data.
146+
This is line 113 of the test data.
147+
This is line 114 of the test data.
148+
This is line 115 of the test data.
149+
This is line 116 of the test data.
150+
This is line 117 of the test data.
151+
This is line 118 of the test data.
152+
This is line 119 of the test data.
153+
This is line 120 of the test data.
154+
This is line 121 of the test data.
155+
This is line 122 of the test data.
156+
This is line 123 of the test data.
157+
This is line 124 of the test data.
158+
This is line 125 of the test data.
159+
This is line 126 of the test data.
160+
This is line 127 of the test data.
161+
This is line 128 of the test data.
162+
This is line 129 of the test data.
163+
This is line 130 of the test data.
164+
This is line 131 of the test data.
165+
This is line 132 of the test data.
166+
This is line 133 of the test data.
167+
This is line 134 of the test data.
168+
This is line 135 of the test data.
169+
This is line 136 of the test data.
170+
This is line 137 of the test data.
171+
This is line 138 of the test data.
172+
This is line 139 of the test data.
173+
This is line 140 of the test data.
174+
This is line 141 of the test data.
175+
This is line 142 of the test data.
176+
This is line 143 of the test data.
177+
This is line 144 of the test data.
178+
This is line 145 of the test data.
179+
This is line 146 of the test data.
180+
This is line 147 of the test data.
181+
This is line 148 of the test data.
182+
This is line 149 of the test data.

ext/ftp/tests/server.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ if ($pid) {
368368
}
369369
fputs($s, "226 Closing data Connection.\r\n");
370370
break;
371+
case "mediumfile":
372+
fputs($s, "150 File status okay; about to open data connection.\r\n");
373+
for($i = 0; $i < 150; $i++){
374+
fputs($fs, "This is line $i of the test data.\n");
375+
}
376+
fputs($s, "226 Closing data Connection.\r\n");
377+
371378
default:
372379
fputs($s, "550 {$matches[1]}: No such file or directory \r\n");
373380
break;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
Bug #64146 (serialize incorrectly saving objects when they are cloned)
3+
--FILE--
4+
<?php
5+
6+
echo "Test\n";
7+
8+
class A
9+
{
10+
public $a = array();
11+
12+
public function __construct()
13+
{
14+
$this->a[] = new B(1);
15+
$this->a[] = new B(2);
16+
}
17+
}
18+
19+
class B implements Serializable
20+
{
21+
public $b;
22+
23+
public function __construct($c)
24+
{
25+
$this->b = new C($c);
26+
}
27+
28+
public function serialize()
29+
{
30+
return serialize(clone $this->b);
31+
}
32+
33+
public function unserialize($data)
34+
{
35+
$this->b = unserialize($data);
36+
}
37+
}
38+
39+
class C
40+
{
41+
public $c;
42+
43+
public function __construct($c)
44+
{
45+
$this->c = $c;
46+
}
47+
}
48+
49+
$a = unserialize(serialize(new A()));
50+
51+
print $a->a[0]->b->c . "\n";
52+
print $a->a[1]->b->c . "\n";
53+
54+
?>
55+
Done
56+
--EXPECT--
57+
Test
58+
1
59+
2
60+
Done
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
--TEST--
2+
Bug #65806 (unserialize fails with object which is referenced multiple times)
3+
--FILE--
4+
<?php
5+
class myObjA {}
6+
class myObjB {
7+
public $attrA;
8+
public $attrB;
9+
}
10+
class myObjC {
11+
public $attrC;
12+
public $attrD;
13+
}
14+
class myList {
15+
private $_serialized;
16+
private $_obj;
17+
18+
public function __construct($obj)
19+
{
20+
$this->_obj = $obj;
21+
$this->_serialized = serialize($this->_obj);
22+
}
23+
public function get()
24+
{
25+
return $this->_obj;
26+
}
27+
public function __sleep()
28+
{
29+
$this->_serialized = serialize($this->_obj);
30+
return array(
31+
"\0" . __CLASS__ . "\0_serialized",
32+
);
33+
}
34+
public function __wakeup()
35+
{
36+
$this->_obj = unserialize($this->_serialized);
37+
}
38+
}
39+
40+
echo "SCRIPT START" . PHP_EOL;
41+
42+
$objA = new myObjA();
43+
$objB = new myObjB();
44+
$objC = new myObjC();
45+
46+
$objB->attrA = new ArrayIterator();
47+
$objB->attrB = $objA;
48+
49+
$objC->attrC = $objB;
50+
$objC->attrD = $objA;
51+
52+
$list = new myList($objC);
53+
54+
echo 'check ' . check($list->get()) . PHP_EOL;
55+
56+
echo "start serialize/unserialize" . PHP_EOL;
57+
$newList = unserialize(serialize($list));
58+
echo "finish serialize/unserialize" . PHP_EOL;
59+
60+
//after unserialize the property myObjC::attrD is null instead of expected object
61+
echo 'check ' . check($newList->get()) . PHP_EOL;
62+
63+
echo "SCRIPT END" . PHP_EOL ;
64+
65+
function check(myObjC $obj) {
66+
67+
if (!is_object($obj->attrC)) {
68+
return 'failed (myObjC::attrC => ' . var_export($obj->attrC, true) . ')';
69+
}
70+
if (!is_object($obj->attrD)) {
71+
return 'failed (myObjC::attrD => ' . var_export($obj->attrD, true) . ')';
72+
}
73+
return 'successful';
74+
}
75+
?>
76+
--EXPECT--
77+
SCRIPT START
78+
check successful
79+
start serialize/unserialize
80+
finish serialize/unserialize
81+
check successful
82+
SCRIPT END
83+

ext/standard/var.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,9 @@ static inline int php_add_var_hash(HashTable *var_hash, zval *var, void *var_old
549549
char id[32], *p;
550550
register int len;
551551

552-
/* relies on "(long)" being a perfect hash function for data pointers,
553-
* however the actual identity of an object has had to be determined
554-
* by its object handle since 5.0. */
555552
if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) {
556-
p = smart_str_print_long(id + sizeof(id) - 1, (long) Z_OBJ_HANDLE_P(var));
553+
p = smart_str_print_long(id + sizeof(id) - 1,
554+
(long) zend_objects_get_address(var TSRMLS_CC));
557555
*(--p) = 'O';
558556
len = id + sizeof(id) - 1 - p;
559557
} else {

0 commit comments

Comments
 (0)