Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -3511,6 +3511,11 @@ zval *date_interval_read_property(zval *object, zval *member, int type TSRMLS_DC

obj = (php_interval_obj *)zend_objects_get_address(object TSRMLS_CC);

if (!obj->initialized) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The DateInterval object has not been correctly initialized by its constructor");
return EG(uninitialized_zval_ptr);
}

#define GET_VALUE_FROM_STRUCT(n,m) \
if (strcmp(Z_STRVAL_P(member), m) == 0) { \
value = obj->diff->n; \
Expand Down Expand Up @@ -3562,6 +3567,12 @@ void date_interval_write_property(zval *object, zval *member, zval *value TSRMLS
}
obj = (php_interval_obj *)zend_objects_get_address(object TSRMLS_CC);


if (!obj->initialized) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The DateInterval object has not been correctly initialized by its constructor");
return;
}

#define SET_VALUE_FROM_STRUCT(n,m) \
if (strcmp(Z_STRVAL_P(member), m) == 0) { \
if (value->type != IS_LONG) { \
Expand Down
44 changes: 44 additions & 0 deletions ext/date/tests/bug62500.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
Bug #62500 (Segfault in DateInterval class when extended)
--FILE--
<?php
class DateCrasher extends DateInterval {
public function __construct($time_spec) {
var_dump($this->y);
$this->y = 3;
var_dump($this->y);
parent::__construct($time_spec);
}
}

$c = new DateCrasher('P2Y4DT6H8M');
var_dump($c);
?>
==DONE==
--EXPECTF--
Warning: DateCrasher::__construct(): The DateInterval object has not been correctly initialized by its constructor in %s on line %d
NULL

Warning: DateCrasher::__construct(): The DateInterval object has not been correctly initialized by its constructor in %s on line %d

Warning: DateCrasher::__construct(): The DateInterval object has not been correctly initialized by its constructor in %s on line %d
NULL
object(DateCrasher)#1 (%d) {
["y"]=>
int(2)
["m"]=>
int(0)
["d"]=>
int(4)
["h"]=>
int(6)
["i"]=>
int(8)
["s"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
bool(false)
}
==DONE==