diff options
author | Tomas Popela <tpopela@redhat.com> | 2018-07-23 09:50:53 +0200 |
---|---|---|
committer | David King <amigadave@amigadave.com> | 2019-01-21 14:38:57 +0000 |
commit | e7f03bfb6e28ebadc1bf5c5b615ad0f90e0e2bb3 (patch) | |
tree | 38fa5b8de5a6039a673b762f0b7dd53095089fd1 /libyelp | |
parent | 48bb6d9c472c0f88731d3d9b04da108b9cdcccdb (diff) | |
download | yelp-e7f03bfb6e28ebadc1bf5c5b615ad0f90e0e2bb3.tar.gz |
Check whether document has a root element before accessing it
yelp-3.28.1/libyelp/yelp-docbook-document.c:562:13: note: Access to field 'ns' results in a dereference of a null pointer (loaded from field 'xmlcur')
if (priv->xmlcur->ns) {
^ ~~~~~~
560| * unique value, and insert it into the in-memory tree */
561| g_snprintf (autoidstr, 20, "//autoid-%d", ++autoid);
562|-> if (priv->xmlcur->ns) {
563| xmlNewNsProp (priv->xmlcur,
564| xmlNewNs (priv->xmlcur, XML_XML_NAMESPACE, BAD_CAST "xml"),
yelp-3.28.1/libyelp/yelp-docbook-document.c:608:16: note: Access to field 'children' results in a dereference of a null pointer (loaded from field 'xmlcur')
for (cur = priv->xmlcur->children; cur; cur = cur->next) {
^ ~~~~~~
606| NULL);
607|
608|-> for (cur = priv->xmlcur->children; cur; cur = cur->next) {
609| if (cur->type == XML_ELEMENT_NODE) {
610| priv->xmlcur = cur;
Diffstat (limited to 'libyelp')
-rw-r--r-- | libyelp/yelp-docbook-document.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libyelp/yelp-docbook-document.c b/libyelp/yelp-docbook-document.c index 893732c0..9557427f 100644 --- a/libyelp/yelp-docbook-document.c +++ b/libyelp/yelp-docbook-document.c @@ -316,6 +316,7 @@ docbook_process (YelpDocbookDocument *docbook) GFile *file = NULL; gchar *filepath = NULL; xmlDocPtr xmldoc = NULL; + xmlNodePtr xmlcur = NULL; xmlChar *id = NULL; xmlParserCtxtPtr parserCtxt = NULL; GError *error; @@ -350,7 +351,10 @@ docbook_process (YelpDocbookDocument *docbook) XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA | XML_PARSE_NOENT | XML_PARSE_NONET ); - if (xmldoc == NULL) { + if (xmldoc) + xmlcur = xmlDocGetRootElement (xmldoc); + + if (xmldoc == NULL || xmlcur == NULL) { error = g_error_new (YELP_ERROR, YELP_ERROR_PROCESSING, _("The file ā%sā could not be parsed because it is" " not a well-formed XML document."), @@ -381,7 +385,7 @@ docbook_process (YelpDocbookDocument *docbook) priv->max_depth = 1; priv->xmldoc = xmldoc; - priv->xmlcur = xmlDocGetRootElement (xmldoc); + priv->xmlcur = xmlcur; id = xmlGetProp (priv->xmlcur, BAD_CAST "id"); if (!id) |