Skip to content

Commit c737b89

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Fixed external entity loading Conflicts: ext/libxml/libxml.c ext/libxml/php_libxml.h
2 parents 021f57e + 8e76d04 commit c737b89

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

ext/libxml/libxml.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ static PHP_GINIT_FUNCTION(libxml)
270270
libxml_globals->error_buffer.c = NULL;
271271
libxml_globals->error_list = NULL;
272272
libxml_globals->entity_loader.fci.size = 0;
273+
libxml_globals->entity_loader_disabled = 0;
273274
}
274275

275276
static void _php_libxml_destroy_fci(zend_fcall_info *fci)
@@ -368,17 +369,16 @@ static int php_libxml_streams_IO_close(void *context)
368369
return php_stream_close((php_stream*)context);
369370
}
370371

371-
static xmlParserInputBufferPtr
372-
php_libxml_input_buffer_noload(const char *URI, xmlCharEncoding enc)
373-
{
374-
return NULL;
375-
}
376-
377372
static xmlParserInputBufferPtr
378373
php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc)
379374
{
380375
xmlParserInputBufferPtr ret;
381376
void *context = NULL;
377+
TSRMLS_FETCH();
378+
379+
if (LIBXML(entity_loader_disabled)) {
380+
return NULL;
381+
}
382382

383383
if (URI == NULL)
384384
return(NULL);
@@ -1052,28 +1052,25 @@ static PHP_FUNCTION(libxml_clear_errors)
10521052
}
10531053
/* }}} */
10541054

1055+
PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable TSRMLS_DC)
1056+
{
1057+
zend_bool old = LIBXML(entity_loader_disabled);
1058+
1059+
LIBXML(entity_loader_disabled) = disable;
1060+
return old;
1061+
}
1062+
10551063
/* {{{ proto bool libxml_disable_entity_loader([boolean disable])
10561064
Disable/Enable ability to load external entities */
10571065
static PHP_FUNCTION(libxml_disable_entity_loader)
10581066
{
10591067
zend_bool disable = 1;
1060-
xmlParserInputBufferCreateFilenameFunc old;
10611068

10621069
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &disable) == FAILURE) {
10631070
return;
10641071
}
10651072

1066-
if (disable == 0) {
1067-
old = xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
1068-
} else {
1069-
old = xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_noload);
1070-
}
1071-
1072-
if (old == php_libxml_input_buffer_noload) {
1073-
RETURN_TRUE;
1074-
}
1075-
1076-
RETURN_FALSE;
1073+
RETURN_BOOL(php_libxml_disable_entity_loader(disable TSRMLS_CC));
10771074
}
10781075
/* }}} */
10791076

ext/libxml/php_libxml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ZEND_BEGIN_MODULE_GLOBALS(libxml)
4747
zend_fcall_info fci;
4848
zend_fcall_info_cache fcc;
4949
} entity_loader;
50+
zend_bool entity_loader_disabled;
5051
ZEND_END_MODULE_GLOBALS(libxml)
5152

5253
typedef struct _libxml_doc_props {
@@ -97,6 +98,7 @@ PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...);
9798
PHP_LIBXML_API int php_libxml_xmlCheckUTF8(const unsigned char *s);
9899
PHP_LIBXML_API zval *php_libxml_switch_context(zval *context TSRMLS_DC);
99100
PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg TSRMLS_DC);
101+
PHP_LIBXML_API zend_bool php_libxml_disable_entity_loader(zend_bool disable TSRMLS_DC);
100102

101103
/* Init/shutdown functions*/
102104
PHP_LIBXML_API void php_libxml_initialize(void);

ext/soap/php_xml.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/* $Id$ */
2121

2222
#include "php_soap.h"
23+
#include "ext/libxml/php_libxml.h"
2324
#include "libxml/parser.h"
2425
#include "libxml/parserInternals.h"
2526

@@ -91,14 +92,17 @@ xmlDocPtr soap_xmlParseFile(const char *filename TSRMLS_DC)
9192
ctxt = xmlCreateFileParserCtxt(filename);
9293
PG(allow_url_fopen) = old_allow_url_fopen;
9394
if (ctxt) {
95+
zend_bool old;
96+
9497
ctxt->keepBlanks = 0;
95-
ctxt->options &= ~XML_PARSE_DTDLOAD;
9698
ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
9799
ctxt->sax->comment = soap_Comment;
98100
ctxt->sax->warning = NULL;
99101
ctxt->sax->error = NULL;
100102
/*ctxt->sax->fatalError = NULL;*/
103+
old = php_libxml_disable_entity_loader(1);
101104
xmlParseDocument(ctxt);
105+
php_libxml_disable_entity_loader(old);
102106
if (ctxt->wellFormed) {
103107
ret = ctxt->myDoc;
104108
if (ret->URL == NULL && ctxt->directory != NULL) {
@@ -134,7 +138,8 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
134138
*/
135139
ctxt = xmlCreateMemoryParserCtxt(buf, buf_size);
136140
if (ctxt) {
137-
ctxt->options &= ~XML_PARSE_DTDLOAD;
141+
zend_bool old;
142+
138143
ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace;
139144
ctxt->sax->comment = soap_Comment;
140145
ctxt->sax->warning = NULL;
@@ -143,7 +148,9 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
143148
#if LIBXML_VERSION >= 20703
144149
ctxt->options |= XML_PARSE_HUGE;
145150
#endif
151+
old = php_libxml_disable_entity_loader(1);
146152
xmlParseDocument(ctxt);
153+
php_libxml_disable_entity_loader(old);
147154
if (ctxt->wellFormed) {
148155
ret = ctxt->myDoc;
149156
if (ret->URL == NULL && ctxt->directory != NULL) {

0 commit comments

Comments
 (0)