Skip to content

Commit c8b0da6

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: Fixed bug #65564 stack-buffer-overflow in DateTimeZone stuff caught by AddressSanitizer Fixed Bug #65564 stack-buffer-overflow in DateTimeZone stuff caught by AddressSanitizer Update NEWS Fixed bug #60598 (cli/apache sapi segfault on objects manipulation)
2 parents a4ff610 + 6fab1ca commit c8b0da6

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
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.5.4
44

55
- Core:
6+
. Fixed bug #60598 (cli/apache sapi segfault on objects manipulation).
7+
(Laruence)
68
. Improved fputcsv() to allow specifying escape character.
79
. Fixed bug #65490 (Duplicate calls to get lineno & filename for
810
DTRACE_FUNCTION_*). (Chris Jones)
@@ -23,6 +25,8 @@ PHP NEWS
2325
- Datetime:
2426
. Fixed bug #65554 (createFromFormat broken when weekday name is followed
2527
by some delimiters). (Valentin Logvinskiy, Stas).
28+
. Fixed bug #65564 (stack-buffer-overflow in DateTimeZone stuff caught
29+
by AddressSanitizer). (Remi).
2630

2731
- OPCache:
2832
. Fixed bug #65561 (Zend Opcache on Solaris 11 x86 needs ZEND_MM_ALIGNMENT=4).

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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,13 +2198,13 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
21982198
/* first we add the date and time in ISO format */
21992199
MAKE_STD_ZVAL(zv);
22002200
ZVAL_STRING(zv, date_format("Y-m-d H:i:s", 12, dateobj->time, 1), 0);
2201-
zend_hash_update(props, "date", 5, &zv, sizeof(zval), NULL);
2201+
zend_hash_update(props, "date", 5, &zv, sizeof(zv), NULL);
22022202

22032203
/* then we add the timezone name (or similar) */
22042204
if (dateobj->time->is_localtime) {
22052205
MAKE_STD_ZVAL(zv);
22062206
ZVAL_LONG(zv, dateobj->time->zone_type);
2207-
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zval), NULL);
2207+
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zv), NULL);
22082208

22092209
MAKE_STD_ZVAL(zv);
22102210
switch (dateobj->time->zone_type) {
@@ -2227,7 +2227,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
22272227
ZVAL_STRING(zv, dateobj->time->tz_abbr, 1);
22282228
break;
22292229
}
2230-
zend_hash_update(props, "timezone", 9, &zv, sizeof(zval), NULL);
2230+
zend_hash_update(props, "timezone", 9, &zv, sizeof(zv), NULL);
22312231
}
22322232

22332233
return props;
@@ -2305,7 +2305,7 @@ static HashTable *date_object_get_properties_timezone(zval *object TSRMLS_DC)
23052305

23062306
MAKE_STD_ZVAL(zv);
23072307
ZVAL_LONG(zv, tzobj->type);
2308-
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zval), NULL);
2308+
zend_hash_update(props, "timezone_type", 14, &zv, sizeof(zv), NULL);
23092309

23102310
MAKE_STD_ZVAL(zv);
23112311
switch (tzobj->type) {
@@ -2327,7 +2327,7 @@ static HashTable *date_object_get_properties_timezone(zval *object TSRMLS_DC)
23272327
ZVAL_STRING(zv, tzobj->tzi.z.abbr, 1);
23282328
break;
23292329
}
2330-
zend_hash_update(props, "timezone", 9, &zv, sizeof(zval), NULL);
2330+
zend_hash_update(props, "timezone", 9, &zv, sizeof(zv), NULL);
23312331

23322332
return props;
23332333
}
@@ -2394,7 +2394,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
23942394
#define PHP_DATE_INTERVAL_ADD_PROPERTY(n,f) \
23952395
MAKE_STD_ZVAL(zv); \
23962396
ZVAL_LONG(zv, (long)intervalobj->diff->f); \
2397-
zend_hash_update(props, n, strlen(n) + 1, &zv, sizeof(zval), NULL);
2397+
zend_hash_update(props, n, strlen(n) + 1, &zv, sizeof(zv), NULL);
23982398

23992399
PHP_DATE_INTERVAL_ADD_PROPERTY("y", y);
24002400
PHP_DATE_INTERVAL_ADD_PROPERTY("m", m);
@@ -2411,7 +2411,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
24112411
} else {
24122412
MAKE_STD_ZVAL(zv);
24132413
ZVAL_FALSE(zv);
2414-
zend_hash_update(props, "days", 5, &zv, sizeof(zval), NULL);
2414+
zend_hash_update(props, "days", 5, &zv, sizeof(zv), NULL);
24152415
}
24162416
PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type);
24172417
PHP_DATE_INTERVAL_ADD_PROPERTY("special_amount", special.amount);

0 commit comments

Comments
 (0)