Skip to content

Commit bfb1fe1

Browse files
committed
Merge branch 'PHP-5.4' of https://git.php.net/repository/php-src into PHP-5.4
* 'PHP-5.4' of https://git.php.net/repository/php-src: Fixed Bug #65564 stack-buffer-overflow in DateTimeZone stuff caught by AddressSanitizer Fixed bug #60598 (cli/apache sapi segfault on objects manipulation)
2 parents 5bff128 + d69513a commit bfb1fe1

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PHP NEWS
33
?? ??? 2013, PHP 5.4.20
44

55
- Core:
6+
. Fixed bug #60598 (cli/apache sapi segfault on objects manipulation).
7+
(Laruence)
68
. Fixed bug #65579 (Using traits with get_class_methods causes segfault).
79
(Adam)
810
. Fixed bug #65490 (Duplicate calls to get lineno & filename for
@@ -34,6 +36,8 @@ PHP NEWS
3436
- Datetime:
3537
. Fixed bug #65554 (createFromFormat broken when weekday name is followed
3638
by some delimiters). (Valentin Logvinskiy, Stas).
39+
. Fixed bug #65564 (stack-buffer-overflow in DateTimeZone stuff caught
40+
by AddressSanitizer). (Remi).
3741

3842
- Openssl:
3943
. Fixed bug #64802 (openssl_x509_parse fails to parse subject properly in

Zend/tests/bug60598.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #60598 (cli/apache sapi segfault on objects manipulation)
3+
--FILE--
4+
<?php
5+
define('OBJECT_COUNT', 10000);
6+
7+
$containers = array();
8+
9+
class Object {
10+
protected $_guid = 0;
11+
public function __construct() {
12+
global $containers;
13+
$this->guid = 1;
14+
$containers[spl_object_hash($this)] = $this;
15+
}
16+
public function __destruct() {
17+
global $containers;
18+
$containers[spl_object_hash($this)] = NULL;
19+
}
20+
}
21+
22+
for ($i = 0; $i < OBJECT_COUNT; ++$i) {
23+
new Object();
24+
}
25+
26+
// You probably won't see this because of the "zend_mm_heap corrupted"
27+
?>
28+
If you see this, try to increase OBJECT_COUNT to 100,000
29+
--EXPECT--
30+
If you see this, try to increase OBJECT_COUNT to 100,000

Zend/zend_objects_API.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects TS
5757
obj->dtor(obj->object, i TSRMLS_CC);
5858
obj = &objects->object_buckets[i].bucket.obj;
5959
obj->refcount--;
60+
61+
if (obj->refcount == 0) {
62+
/* in case gc_collect_cycle is triggered before free_storage */
63+
GC_REMOVE_ZOBJ_FROM_BUFFER(obj);
64+
}
6065
}
6166
}
6267
}

ext/date/php_date.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,13 +2113,13 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
21132113
/* first we add the date and time in ISO format */
21142114
MAKE_STD_ZVAL(zv);
21152115
ZVAL_STRING(zv, date_format("Y-m-d H:i:s", 12, dateobj->time, 1), 0);
2116-
zend_hash_update(props, "date", 5, &zv, sizeof(zval), NULL);
2116+
zend_hash_update(props, "date", 5, &zv, sizeof(zv), NULL);
21172117

21182118
/* then we add the timezone name (or similar) */
21192119
if (dateobj->time->is_localtime) {
21202120
MAKE_STD_ZVAL(zv);
21212121
ZVAL_LONG(zv, dateobj->time->zone_type);
2122-
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zval), NULL);
2122+
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zv), NULL);
21232123

21242124
MAKE_STD_ZVAL(zv);
21252125
switch (dateobj->time->zone_type) {
@@ -2142,7 +2142,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
21422142
ZVAL_STRING(zv, dateobj->time->tz_abbr, 1);
21432143
break;
21442144
}
2145-
zend_hash_update(props, "timezone", 9, &zv, sizeof(zval), NULL);
2145+
zend_hash_update(props, "timezone", 9, &zv, sizeof(zv), NULL);
21462146
}
21472147

21482148
return props;
@@ -2265,7 +2265,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
22652265
#define PHP_DATE_INTERVAL_ADD_PROPERTY(n,f) \
22662266
MAKE_STD_ZVAL(zv); \
22672267
ZVAL_LONG(zv, (long)intervalobj->diff->f); \
2268-
zend_hash_update(props, n, strlen(n) + 1, &zv, sizeof(zval), NULL);
2268+
zend_hash_update(props, n, strlen(n) + 1, &zv, sizeof(zv), NULL);
22692269

22702270
PHP_DATE_INTERVAL_ADD_PROPERTY("y", y);
22712271
PHP_DATE_INTERVAL_ADD_PROPERTY("m", m);
@@ -2282,7 +2282,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
22822282
} else {
22832283
MAKE_STD_ZVAL(zv);
22842284
ZVAL_FALSE(zv);
2285-
zend_hash_update(props, "days", 5, &zv, sizeof(zval), NULL);
2285+
zend_hash_update(props, "days", 5, &zv, sizeof(zv), NULL);
22862286
}
22872287
PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type);
22882288
PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount);

0 commit comments

Comments
 (0)