[libgrss] src: Add missing NULL checks for XML elements
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgrss] src: Add missing NULL checks for XML elements
- Date: Thu, 16 Feb 2017 20:20:56 +0000 (UTC)
commit 9a9376c1c09486a450ecbf89c3c9483954bd7ae9
Author: Philip Withnall <withnall endlessm com>
Date: Wed Dec 21 16:49:14 2016 +0000
src: Add missing NULL checks for XML elements
If the loop to skip blank elements ends up reading the entire document,
cur will be set to NULL, and the following code (which dereferences its
elements) will crash. Avoid that by checking cur again.
Coverity IDs: 1388544, 1388545, 1388548
https://bugzilla.gnome.org/show_bug.cgi?id=776115
src/feed-atom-handler.c | 2 +-
src/feed-pie-handler.c | 2 +-
src/feed-rss-handler.c | 9 +++++----
3 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/src/feed-atom-handler.c b/src/feed-atom-handler.c
index 7a20662..f8cf47c 100644
--- a/src/feed-atom-handler.c
+++ b/src/feed-atom-handler.c
@@ -782,7 +782,7 @@ feed_atom_handler_parse (FeedHandler *self, GrssFeedChannel *feed, xmlDocPtr doc
parser = FEED_ATOM_HANDLER (self);
while (TRUE) {
- if (xmlStrcmp (cur->name, BAD_CAST"feed")) {
+ if (!cur || xmlStrcmp (cur->name, BAD_CAST"feed")) {
g_set_error (error, FEED_ATOM_HANDLER_ERROR, FEED_ATOM_HANDLER_PARSE_ERROR, "Could
not find Atom 1.0 header!");
break;
}
diff --git a/src/feed-pie-handler.c b/src/feed-pie-handler.c
index b15e192..26c4738 100644
--- a/src/feed-pie-handler.c
+++ b/src/feed-pie-handler.c
@@ -326,7 +326,7 @@ feed_pie_handler_parse (FeedHandler *self, GrssFeedChannel *feed, xmlDocPtr doc,
cur = cur->next;
while (TRUE) {
- if (xmlStrcmp (cur->name, BAD_CAST"feed")) {
+ if (!cur || xmlStrcmp (cur->name, BAD_CAST"feed")) {
g_set_error (error, FEED_PIE_HANDLER_ERROR, FEED_PIE_HANDLER_PARSE_ERROR, "Could not
find Atom/PIE header!");
break;
}
diff --git a/src/feed-rss-handler.c b/src/feed-rss-handler.c
index 879e9ff..efcc300 100644
--- a/src/feed-rss-handler.c
+++ b/src/feed-rss-handler.c
@@ -452,16 +452,17 @@ feed_rss_handler_parse (FeedHandler *self, GrssFeedChannel *feed, xmlDocPtr doc,
while (cur && xmlIsBlankNode (cur))
cur = cur->next;
- if (!xmlStrcmp (cur->name, BAD_CAST"rss")) {
+ if (cur && !xmlStrcmp (cur->name, BAD_CAST"rss")) {
cur = cur->xmlChildrenNode;
rdf = FALSE;
}
- else if (!xmlStrcmp (cur->name, BAD_CAST"rdf") ||
- !xmlStrcmp (cur->name, BAD_CAST"RDF")) {
+ else if (cur &&
+ (!xmlStrcmp (cur->name, BAD_CAST"rdf") ||
+ !xmlStrcmp (cur->name, BAD_CAST"RDF"))) {
cur = cur->xmlChildrenNode;
rdf = TRUE;
}
- else if (!xmlStrcmp (cur->name, BAD_CAST"Channel")) {
+ else if (cur && !xmlStrcmp (cur->name, BAD_CAST"Channel")) {
rdf = FALSE;
}
else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]