summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2016-10-11 13:30:52 -0700
committerAnatol Belski <ab@php.net>2016-10-13 00:35:06 +0200
commit850504ae7d1ab97299b6ad1776a580e714526328 (patch)
treecf1b775b4f88e3d4f42581b818e420ef37d2ffd6
parent9557f711d475a9f99509c7d5eb792a56b833aa25 (diff)
downloadphp-git-850504ae7d1ab97299b6ad1776a580e714526328.tar.gz
Fix bug #73293 - NULL pointer dereference in SimpleXMLElement::asXML()
(cherry picked from commit 96a8cf8e1b5dc1b0c708bb5574e0d6727cc56d9e) (cherry picked from commit 4ef79370a82d6c92f4ea0cd462274ba24e007f56)
-rw-r--r--ext/simplexml/simplexml.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index a20cb3e22a..6a05f04618 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1472,9 +1472,15 @@ SXE_METHOD(asXML)
if (node) {
if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) {
xmlDocDumpMemoryEnc((xmlDocPtr) sxe->document->ptr, &strval, &strval_len, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding);
- RETVAL_STRINGL((char *)strval, strval_len);
+ if (!strval) {
+ RETVAL_FALSE;
+ } else {
+ RETVAL_STRINGL((char *)strval, strval_len);
+ }
xmlFree(strval);
} else {
+ char *return_content;
+ size_t return_len;
/* Should we be passing encoding information instead of NULL? */
outbuf = xmlAllocOutputBuffer(NULL);
@@ -1485,10 +1491,17 @@ SXE_METHOD(asXML)
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding);
xmlOutputBufferFlush(outbuf);
#ifdef LIBXML2_NEW_BUFFER
- RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf), xmlOutputBufferGetSize(outbuf));
+ return_content = (char *)xmlOutputBufferGetContent(outbuf);
+ return_len = xmlOutputBufferGetSize(outbuf);
#else
- RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use);
+ return_content = (char *)outbuf->buffer->content;
+ return_len = outbuf->buffer->use;
#endif
+ if (return_content) {
+ RETVAL_FALSE;
+ } else {
+ RETVAL_STRINGL(return_content, return_len);
+ }
xmlOutputBufferClose(outbuf);
}
} else {