Handle NULL data from XML parser in order to cope
authorArt Cancro <ajc@citadel.org>
Sun, 4 Nov 2007 03:55:10 +0000 (03:55 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 4 Nov 2007 03:55:10 +0000 (03:55 +0000)
with the Homeland Stupidity RSS feed, which IO deliberately
configured in such a way to crash Citadel and prove that our
parser wasn't yet ready for prime time.   :)

citadel/modules/rssclient/serv_rssclient.c
citadel/tools.c

index 906e2787c60eba39dc9a3616faacfd627f945816..8ba42762c249f75599f9552b367241d47ca566b9 100644 (file)
@@ -252,35 +252,35 @@ void rss_xml_end(void *data, const char *supplied_el) {
                strcpy(el, ++sep);
        }
 
-       if ( (!strcasecmp(el, "title")) && (ri->item_tag_nesting == 0) ) {
+       if ( (!strcasecmp(el, "title")) && (ri->item_tag_nesting == 0) && (ri->chardata != NULL) ) {
                safestrncpy(ri->channel_title, ri->chardata, sizeof ri->channel_title);
                striplt(ri->channel_title);
        }
 
-       if (!strcasecmp(el, "guid")) {
+       if ( (!strcasecmp(el, "guid")) && (ri->chardata != NULL) ) {
                if (ri->guid != NULL) free(ri->guid);
                striplt(ri->chardata);
                ri->guid = strdup(ri->chardata);
        }
 
-       if (!strcasecmp(el, "title")) {
+       if ( (!strcasecmp(el, "title")) && (ri->chardata != NULL) ) {
                if (ri->title != NULL) free(ri->title);
                striplt(ri->chardata);
                ri->title = strdup(ri->chardata);
        }
 
-       if (!strcasecmp(el, "link")) {
+       if ( (!strcasecmp(el, "link")) && (ri->chardata != NULL) ) {
                if (ri->link != NULL) free(ri->link);
                striplt(ri->chardata);
                ri->link = strdup(ri->chardata);
        }
 
-       if (!strcasecmp(el, "description")) {
+       if ( (!strcasecmp(el, "description")) && (ri->chardata != NULL) ) {
                if (ri->description != NULL) free(ri->description);
                ri->description = strdup(ri->chardata);
        }
 
-       if ( (!strcasecmp(el, "pubdate")) || (!strcasecmp(el, "date")) ) {
+       if ( ((!strcasecmp(el, "pubdate")) || (!strcasecmp(el, "date"))) && (ri->chardata != NULL) ) {
                striplt(ri->chardata);
                ri->pubdate = rdf_parsedate(ri->chardata);
        }
index cd8f1510d5ae9a897b8782d79b788e12b879993b..725b9daed1508c20ef9d2cb9d203e9b4acb77095 100644 (file)
@@ -453,6 +453,8 @@ void striplt(char *buf)
 {
        size_t len;
        int a;
+
+       if (buf==NULL) return;
        if (IsEmptyStr(buf)) return;
        len = strlen(buf);
         while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))