Skip to content

Commit cad47be

Browse files
committed
Fix phpGH-11548 (Argument corruption when calling XMLReader::open or XMLReader::XML non-statically with observer active)
1 parent 04cd885 commit cad47be

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ PHP NEWS
3232
- Standard:
3333
. Fix serialization of RC1 objects appearing in object graph twice. (ilutov)
3434

35+
- XMLReader:
36+
. Fix GH-11548 (Argument corruption when calling XMLReader::open or
37+
XMLReader::XML non-statically with observer active). (Bob)
38+
3539
06 Jul 2023, PHP 8.2.8
3640

3741
- CLI:

ext/xmlreader/php_xmlreader.c

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "php.h"
2323
#include "php_ini.h"
2424
#include "ext/standard/info.h"
25+
#include "zend_observer.h"
2526
#include "php_xmlreader.h"
2627
#ifdef HAVE_DOM
2728
#include "ext/dom/xml_common.h"
@@ -1148,6 +1149,18 @@ PHP_METHOD(XMLReader, expand)
11481149
}
11491150
/* }}} */
11501151

1152+
static zend_result (*prev_zend_post_startup_cb)(void);
1153+
static zend_result xmlreader_fixup_temporaries(void) {
1154+
if (ZEND_OBSERVER_ENABLED) {
1155+
++xmlreader_open_fn.T;
1156+
++xmlreader_xml_fn.T;
1157+
}
1158+
if (prev_zend_post_startup_cb) {
1159+
return prev_zend_post_startup_cb();
1160+
}
1161+
return SUCCESS;
1162+
}
1163+
11511164
/* {{{ PHP_MINIT_FUNCTION */
11521165
PHP_MINIT_FUNCTION(xmlreader)
11531166
{
@@ -1169,6 +1182,9 @@ PHP_MINIT_FUNCTION(xmlreader)
11691182
memcpy(&xmlreader_xml_fn, zend_hash_str_find_ptr(&xmlreader_class_entry->function_table, "xml", sizeof("xml")-1), sizeof(zend_internal_function));
11701183
xmlreader_xml_fn.fn_flags &= ~ZEND_ACC_STATIC;
11711184

1185+
prev_zend_post_startup_cb = zend_post_startup_cb;
1186+
zend_post_startup_cb = xmlreader_fixup_temporaries;
1187+
11721188
zend_hash_init(&xmlreader_prop_handlers, 0, NULL, php_xmlreader_free_prop_handler, 1);
11731189
xmlreader_register_prop_handler(&xmlreader_prop_handlers, "attributeCount", xmlTextReaderAttributeCount, NULL, IS_LONG);
11741190
xmlreader_register_prop_handler(&xmlreader_prop_handlers, "baseURI", NULL, xmlTextReaderConstBaseUri, IS_STRING);

0 commit comments

Comments
 (0)