]> granicus.if.org Git - php/commitdiff
Fixed external entity loading
authorDmitry Stogov <dmitry@zend.com>
Wed, 20 Feb 2013 18:14:59 +0000 (22:14 +0400)
committerDmitry Stogov <dmitry@zend.com>
Wed, 20 Feb 2013 18:14:59 +0000 (22:14 +0400)
ext/libxml/libxml.c
ext/libxml/php_libxml.h
ext/soap/php_xml.c

index 5db1f31ea958b9a7e06e282e743106611648d940..920a90c634922e788fdee9b789aab803fbdd0f51 100644 (file)
@@ -261,6 +261,7 @@ static PHP_GINIT_FUNCTION(libxml)
        libxml_globals->stream_context = NULL;
        libxml_globals->error_buffer.c = NULL;
        libxml_globals->error_list = NULL;
+       libxml_globals->entity_loader_disabled = 0;
 }
 
 /* Channel libxml file io layer through the PHP streams subsystem.
@@ -347,17 +348,16 @@ static int php_libxml_streams_IO_close(void *context)
        return php_stream_close((php_stream*)context);
 }
 
-static xmlParserInputBufferPtr
-php_libxml_input_buffer_noload(const char *URI, xmlCharEncoding enc)
-{
-       return NULL;
-}
-
 static xmlParserInputBufferPtr
 php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc)
 {
        xmlParserInputBufferPtr ret;
        void *context = NULL;
+       TSRMLS_FETCH();
+
+       if (LIBXML(entity_loader_disabled)) {
+               return NULL;
+       }
 
        if (URI == NULL)
                return(NULL);
@@ -834,28 +834,25 @@ static PHP_FUNCTION(libxml_clear_errors)
 }
 /* }}} */
 
+PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable TSRMLS_DC)
+{
+       zend_bool old = LIBXML(entity_loader_disabled);
+
+       LIBXML(entity_loader_disabled) = disable;
+       return old;
+}
+
 /* {{{ proto bool libxml_disable_entity_loader([boolean disable]) 
    Disable/Enable ability to load external entities */
 static PHP_FUNCTION(libxml_disable_entity_loader)
 {
        zend_bool disable = 1;
-       xmlParserInputBufferCreateFilenameFunc old;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &disable) == FAILURE) {
                return;
        }
 
-       if (disable == 0) {
-               old = xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
-       } else {
-               old = xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_noload);
-       }
-
-       if (old == php_libxml_input_buffer_noload) {
-               RETURN_TRUE;
-       }
-
-       RETURN_FALSE;
+       RETURN_BOOL(php_libxml_disable_entity_loader(disable TSRMLS_CC));
 }
 /* }}} */
 
index 91a6d247ba3dee245526b122ffee08c5816409e8..a7d84666f49509f4135eb6353a44d1c0372c59ce 100644 (file)
@@ -43,6 +43,7 @@ ZEND_BEGIN_MODULE_GLOBALS(libxml)
        zval *stream_context;
        smart_str error_buffer;
        zend_llist *error_list;
+       zend_bool entity_loader_disabled;
 ZEND_END_MODULE_GLOBALS(libxml)
 
 typedef struct _libxml_doc_props {
@@ -93,6 +94,7 @@ PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...);
 PHP_LIBXML_API int php_libxml_xmlCheckUTF8(const unsigned char *s);
 PHP_LIBXML_API zval *php_libxml_switch_context(zval *context TSRMLS_DC);
 PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg TSRMLS_DC);
+PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable TSRMLS_DC);
 
 /* Init/shutdown functions*/
 PHP_LIBXML_API void php_libxml_initialize(void);
index 006db854e439af8cdb8fa748465ffb42bf0485f0..78231000a0baf8a0754f18cbd45e7cee5497dc6f 100644 (file)
@@ -20,6 +20,7 @@
 /* $Id$ */
 
 #include "php_soap.h"
+#include "ext/libxml/php_libxml.h"
 #include "libxml/parser.h"
 #include "libxml/parserInternals.h"
 
@@ -91,14 +92,17 @@ xmlDocPtr soap_xmlParseFile(const char *filename TSRMLS_DC)
        ctxt = xmlCreateFileParserCtxt(filename);
        PG(allow_url_fopen) = old_allow_url_fopen;
        if (ctxt) {
+               zend_bool old;
+
                ctxt->keepBlanks = 0;
-               ctxt->options &= ~XML_PARSE_DTDLOAD;
                ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
                ctxt->sax->comment = soap_Comment;
                ctxt->sax->warning = NULL;
                ctxt->sax->error = NULL;
                /*ctxt->sax->fatalError = NULL;*/
+               old = php_libxml_disable_entity_loader(1);
                xmlParseDocument(ctxt);
+               php_libxml_disable_entity_loader(old);
                if (ctxt->wellFormed) {
                        ret = ctxt->myDoc;
                        if (ret->URL == NULL && ctxt->directory != NULL) {
@@ -134,7 +138,8 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
 */
        ctxt = xmlCreateMemoryParserCtxt(buf, buf_size);
        if (ctxt) {
-               ctxt->options &= ~XML_PARSE_DTDLOAD;
+               zend_bool old;
+
                ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
                ctxt->sax->comment = soap_Comment;
                ctxt->sax->warning = NULL;
@@ -143,7 +148,9 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
 #if LIBXML_VERSION >= 20703
                ctxt->options |= XML_PARSE_HUGE;
 #endif
+               old = php_libxml_disable_entity_loader(1);
                xmlParseDocument(ctxt);
+               php_libxml_disable_entity_loader(old);
                if (ctxt->wellFormed) {
                        ret = ctxt->myDoc;
                        if (ret->URL == NULL && ctxt->directory != NULL) {