From b9b81b9b8a34f5b3a9069c111c4d7530d73a04ce Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 24 Aug 2016 22:52:12 +0100 Subject: protect expat parser from null current node --- bindings/xml/expat_xmlparser.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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, -- cgit v1.2.3