summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-08-24 21:52:12 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2016-08-24 21:52:12 (GMT)
commitb9b81b9b8a34f5b3a9069c111c4d7530d73a04ce (patch)
tree168a0dfce6ae62979a451d459ef8c5f1c6ff3854
parentd055eaf25d60a1c1538bacc32d5e51a073477ebb (diff)
downloadlibdom-b9b81b9b8a34f5b3a9069c111c4d7530d73a04ce.tar.gz
libdom-b9b81b9b8a34f5b3a9069c111c4d7530d73a04ce.tar.bz2
protect expat parser from null current node
-rw-r--r--bindings/xml/expat_xmlparser.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/bindings/xml/expat_xmlparser.c b/bindings/xml/expat_xmlparser.c
index e1c22ad..4bdd5c9 100644
--- a/bindings/xml/expat_xmlparser.c
+++ b/bindings/xml/expat_xmlparser.c
@@ -45,6 +45,11 @@ expat_xmlparser_start_element_handler(void *_parser,
dom_string *namespace = NULL;
const XML_Char *ns_sep = strchr(name, '\n');
+ if (parser->current == NULL) {
+ /* not currently building a node so cannot add elemnt to it */
+ return;
+ }
+
if (ns_sep != NULL) {
err = dom_string_create_interned((const uint8_t *)name,
ns_sep - name,
@@ -174,6 +179,13 @@ expat_xmlparser_end_element_handler(void *_parser,
UNUSED(name);
+ if (parser->current == NULL) {
+ /* not currently building a node so cannot end elemnt
+ * addition to it.
+ */
+ return;
+ }
+
err = dom_node_get_parent_node(parser->current, &parent);
if (err != DOM_NO_ERR) {
@@ -213,6 +225,11 @@ expat_xmlparser_cdata_handler(void *_parser,
struct dom_node *cdata, *ins_cdata, *lastchild = NULL;
dom_node_type ntype = 0;
+ if (parser->current == NULL) {
+ /* not currently building a node so cannot add cdata to it */
+ return;
+ }
+
err = dom_string_create((const uint8_t *)s, len, &data);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,