@@ -74,19 +74,11 @@ static void soap_Comment(void *ctx, const xmlChar *value)
7474{
7575}
7676
77- xmlDocPtr soap_xmlParseFile (const char * filename )
77+ /* Consumes `ctxt` */
78+ static xmlDocPtr soap_xmlParse_ex (xmlParserCtxtPtr ctxt )
7879{
79- xmlParserCtxtPtr ctxt = NULL ;
8080 xmlDocPtr ret ;
81- bool old_allow_url_fopen ;
82-
83- old_allow_url_fopen = PG (allow_url_fopen );
84- PG (allow_url_fopen ) = 1 ;
85- ctxt = xmlCreateFileParserCtxt (filename );
86- PG (allow_url_fopen ) = old_allow_url_fopen ;
8781 if (ctxt ) {
88- bool old ;
89-
9082 php_libxml_sanitize_parse_ctxt_options (ctxt );
9183 /* TODO: In libxml2 2.14.0 change this to the new options API so we don't rely on deprecated APIs. */
9284 ZEND_DIAGNOSTIC_IGNORED_START ("-Wdeprecated-declarations" )
@@ -98,7 +90,7 @@ xmlDocPtr soap_xmlParseFile(const char *filename)
9890 ctxt -> sax -> warning = NULL ;
9991 ctxt -> sax -> error = NULL ;
10092 /*ctxt->sax->fatalError = NULL;*/
101- old = php_libxml_disable_entity_loader (1 );
93+ bool old = php_libxml_disable_entity_loader (true );
10294 xmlParseDocument (ctxt );
10395 php_libxml_disable_entity_loader (old );
10496 if (ctxt -> wellFormed ) {
@@ -115,6 +107,17 @@ xmlDocPtr soap_xmlParseFile(const char *filename)
115107 } else {
116108 ret = NULL ;
117109 }
110+ return ret ;
111+ }
112+
113+ xmlDocPtr soap_xmlParseFile (const char * filename )
114+ {
115+ bool old_allow_url_fopen = PG (allow_url_fopen );
116+ PG (allow_url_fopen ) = true;
117+ xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt (filename );
118+ PG (allow_url_fopen ) = old_allow_url_fopen ;
119+
120+ xmlDocPtr ret = soap_xmlParse_ex (ctxt );
118121
119122 if (ret ) {
120123 cleanup_xml_node ((xmlNodePtr )ret );
@@ -124,40 +127,8 @@ xmlDocPtr soap_xmlParseFile(const char *filename)
124127
125128xmlDocPtr soap_xmlParseMemory (const void * buf , size_t buf_size )
126129{
127- xmlParserCtxtPtr ctxt = NULL ;
128- xmlDocPtr ret ;
129-
130- ctxt = xmlCreateMemoryParserCtxt (buf , buf_size );
131- if (ctxt ) {
132- bool old ;
133-
134- php_libxml_sanitize_parse_ctxt_options (ctxt );
135- ctxt -> sax -> ignorableWhitespace = soap_ignorableWhitespace ;
136- ctxt -> sax -> comment = soap_Comment ;
137- ctxt -> sax -> warning = NULL ;
138- ctxt -> sax -> error = NULL ;
139- /*ctxt->sax->fatalError = NULL;*/
140- /* TODO: In libxml2 2.14.0 change this to the new options API so we don't rely on deprecated APIs. */
141- ZEND_DIAGNOSTIC_IGNORED_START ("-Wdeprecated-declarations" )
142- ctxt -> options |= XML_PARSE_HUGE ;
143- ZEND_DIAGNOSTIC_IGNORED_END
144- old = php_libxml_disable_entity_loader (1 );
145- xmlParseDocument (ctxt );
146- php_libxml_disable_entity_loader (old );
147- if (ctxt -> wellFormed ) {
148- ret = ctxt -> myDoc ;
149- if (ret -> URL == NULL && ctxt -> directory != NULL ) {
150- ret -> URL = xmlCharStrdup (ctxt -> directory );
151- }
152- } else {
153- ret = NULL ;
154- xmlFreeDoc (ctxt -> myDoc );
155- ctxt -> myDoc = NULL ;
156- }
157- xmlFreeParserCtxt (ctxt );
158- } else {
159- ret = NULL ;
160- }
130+ xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt (buf , buf_size );
131+ xmlDocPtr ret = soap_xmlParse_ex (ctxt );
161132
162133/*
163134 if (ret) {
0 commit comments