Skip to content

Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault #18307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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
4 changes: 3 additions & 1 deletion ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -4399,7 +4399,9 @@ static zval *date_interval_get_property_ptr_ptr(zend_object *object, zend_string
zend_string_equals_literal(name, "days") ||
zend_string_equals_literal(name, "invert") ) {
/* Fallback to read_property. */
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}
ret = NULL;
} else {
ret = zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
Expand Down
35 changes: 35 additions & 0 deletions ext/date/tests/gh18304.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
GH-18304 (Changing the properties of a DateInterval through dynamic properties triggers a SegFault)
--CREDITS--
orose-assetgo
--FILE--
<?php
$di = new \DateInterval('P0Y');
$field = 'd';
$i = 1;
$di->$field += $i;
var_dump($di);
?>
--EXPECT--
object(DateInterval)#1 (10) {
["y"]=>
int(0)
["m"]=>
int(0)
["d"]=>
int(1)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
bool(false)
["from_string"]=>
bool(false)
}
4 changes: 3 additions & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ static zval *dom_get_property_ptr_ptr(zend_object *object, zend_string *name, in
return zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
}

cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}
return NULL;
}

Expand Down
15 changes: 15 additions & 0 deletions ext/dom/tests/gh18304.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
GH-18304 (Changing the properties of a DateInterval through dynamic properties triggers a SegFault)
--CREDITS--
orose-assetgo
--EXTENSIONS--
dom
--FILE--
<?php
$text = new \DOMText();
$field = 'textContent';
$text->$field .= 'hello';
var_dump($text->$field);
?>
--EXPECT--
string(5) "hello"
5 changes: 3 additions & 2 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2493,9 +2493,10 @@ static zval *pdo_row_get_property_ptr_ptr(zend_object *object, zend_string *name
ZEND_IGNORE_VALUE(object);
ZEND_IGNORE_VALUE(name);
ZEND_IGNORE_VALUE(type);
ZEND_IGNORE_VALUE(cache_slot);

cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}
return NULL;
}

Expand Down
4 changes: 3 additions & 1 deletion ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int f
SXE_ITER type;
zval member;

cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}

sxe = php_sxe_fetch_object(object);
GET_NODE(sxe, node);
Expand Down
18 changes: 18 additions & 0 deletions ext/simplexml/tests/gh18304.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-18304 (Changing the properties of a DateInterval through dynamic properties triggers a SegFault)
--CREDITS--
orose-assetgo
--EXTENSIONS--
simplexml
--FILE--
<?php
$sxe = simplexml_load_string('<root><abc/></root>');
$field = 'abc';
$sxe->$field .= 'hello';
var_dump($sxe->$field);
?>
--EXPECT--
object(SimpleXMLElement)#3 (1) {
[0]=>
string(5) "hello"
}
4 changes: 3 additions & 1 deletion ext/snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,9 @@ static zval *php_snmp_get_property_ptr_ptr(zend_object *object, zend_string *nam
return zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
}

cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}
return NULL;
}

Expand Down
15 changes: 15 additions & 0 deletions ext/snmp/tests/gh18304.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
GH-18304 (Changing the properties of a DateInterval through dynamic properties triggers a SegFault)
--CREDITS--
orose-assetgo
--EXTENSIONS--
snmp
--FILE--
<?php
$snmp = new SNMP(1, '127.0.0.1', 'community');
$field = 'max_oids';
$snmp->$field++;
var_dump($snmp->$field);
?>
--EXPECT--
int(1)
4 changes: 3 additions & 1 deletion ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,9 @@ static zval *spl_array_get_property_ptr_ptr(zend_object *object, zend_string *na

if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0
&& !zend_std_has_property(object, name, ZEND_PROPERTY_EXISTS, NULL)) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}

/* If object has offsetGet() overridden, then fallback to read_property,
* which will call offsetGet(). */
Expand Down
14 changes: 14 additions & 0 deletions ext/spl/tests/gh18304.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-18304 (Changing the properties of a DateInterval through dynamic properties triggers a SegFault)
--CREDITS--
orose-assetgo
--FILE--
<?php
$ao = new ArrayObject(['abc' => 1]);
$ao->setFlags(ArrayObject::ARRAY_AS_PROPS);
$field = 'abc';
$ao->$field++;
var_dump($ao->$field);
?>
--EXPECT--
int(2)
4 changes: 2 additions & 2 deletions ext/xmlreader/php_xmlreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ zval *xmlreader_get_property_ptr_ptr(zend_object *object, zend_string *name, int
zval *retval = NULL;
xmlreader_prop_handler *hnd = NULL;

cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;

obj = php_xmlreader_fetch_object(object);

if (obj->prop_handler != NULL) {
Expand All @@ -131,6 +129,8 @@ zval *xmlreader_get_property_ptr_ptr(zend_object *object, zend_string *name, int

if (hnd == NULL) {
retval = zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
} else if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}

return retval;
Expand Down
4 changes: 2 additions & 2 deletions ext/zip/php_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,6 @@ static zval *php_zip_get_property_ptr_ptr(zend_object *object, zend_string *name
zval *retval = NULL;
zip_prop_handler *hnd = NULL;

cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;

obj = php_zip_fetch_object(object);

if (obj->prop_handler != NULL) {
Expand All @@ -900,6 +898,8 @@ static zval *php_zip_get_property_ptr_ptr(zend_object *object, zend_string *name

if (hnd == NULL) {
retval = zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
} else if (cache_slot) {
cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
}

return retval;
Expand Down
Loading