File tree Expand file tree Collapse file tree 3 files changed +68
-1
lines changed Expand file tree Collapse file tree 3 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ PHP NEWS
16
16
. Fixed bug GH-18529 (additional inheriting of TLS int options).
17
17
(Jakub Zelenka)
18
18
19
+ - LibXML:
20
+ . Fixed bug GH-19098 (libxml<2.13 segmentation fault caused by
21
+ php_libxml_node_free). (nielsdos)
22
+
19
23
- OpenSSL:
20
24
. Fixed bug GH-18986 (OpenSSL backend: incorrect RAND_{load,write}_file()
21
25
return value check). (nielsdos, botovq)
Original file line number Diff line number Diff line change @@ -341,7 +341,26 @@ PHP_LIBXML_API void php_libxml_node_free_list(xmlNodePtr node)
341
341
if (ptr -> _private ) {
342
342
php_libxml_node_object * obj = ptr -> _private ;
343
343
if (!obj -> document || obj -> document -> class_type < PHP_LIBXML_CLASS_MODERN ) {
344
- xmlReconciliateNs (curnode -> doc , curnode );
344
+ if (LIBXML_VERSION < 21300 && UNEXPECTED (curnode -> doc == NULL )) {
345
+ /* xmlReconciliateNs() in these versions just uses the document for xmlNewReconciledNs(),
346
+ * which can create an oldNs xml namespace declaration via xmlSearchNs() -> xmlTreeEnsureXMLDecl(). */
347
+ xmlDoc dummy ;
348
+ memset (& dummy , 0 , sizeof (dummy ));
349
+ dummy .type = XML_DOCUMENT_NODE ;
350
+ curnode -> doc = & dummy ;
351
+ xmlReconciliateNs (curnode -> doc , curnode );
352
+ curnode -> doc = NULL ;
353
+
354
+ /* Append oldNs to current node's nsDef, which can be at most one node. */
355
+ if (dummy .oldNs ) {
356
+ ZEND_ASSERT (dummy .oldNs -> next == NULL );
357
+ xmlNsPtr old = curnode -> nsDef ;
358
+ curnode -> nsDef = dummy .oldNs ;
359
+ dummy .oldNs -> next = old ;
360
+ }
361
+ } else {
362
+ xmlReconciliateNs (curnode -> doc , curnode );
363
+ }
345
364
}
346
365
}
347
366
}
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-19098 (libxml<2.13 segmentation fault caused by php_libxml_node_free)
3
+ --EXTENSIONS--
4
+ xmlreader
5
+ dom
6
+ --FILE--
7
+ <?php
8
+
9
+ $ xml_reader = \XMLReader::XML ('
10
+ <sparql xmlns="http://www.w3.org/2005/sparql-results#">
11
+ <results>
12
+ <result><binding xml:id="foo" xmlns:custom="urn:custom" custom:foo="bar" name="s"><uri/></binding></result>
13
+ </results>
14
+ </sparql> ' );
15
+
16
+ $ success = $ xml_reader ->next ("sparql " );
17
+
18
+ $ success = $ xml_reader ->read ();
19
+ $ success = $ xml_reader ->next ("results " );
20
+
21
+ while ($ xml_reader ->read ()) {
22
+ if ($ xml_reader ->next ("result " )) {
23
+ $ result_as_dom_node = $ xml_reader ->expand ();
24
+ $ child = $ result_as_dom_node ->firstChild ;
25
+ unset($ result_as_dom_node );
26
+ var_dump ($ child ->namespaceURI );
27
+ foreach ($ child ->attributes as $ attr ) {
28
+ var_dump ($ attr ->namespaceURI );
29
+ }
30
+ $ doc = new DOMDocument ;
31
+ $ doc ->adoptNode ($ child );
32
+ echo $ doc ->saveXML ($ child ), "\n" ;
33
+ unset($ child );
34
+ break ;
35
+ }
36
+ }
37
+
38
+ ?>
39
+ --EXPECT--
40
+ string(38) "http://www.w3.org/2005/sparql-results#"
41
+ string(36) "http://www.w3.org/XML/1998/namespace"
42
+ string(10) "urn:custom"
43
+ NULL
44
+ <default:binding xmlns:custom="urn:custom" xmlns:default="http://www.w3.org/2005/sparql-results#" xml:id="foo" custom:foo="bar" name="s"><default:uri/></default:binding>
You can’t perform that action at this time.
0 commit comments