RSSyl: more fixes for Coverity issues
authorAndrej Kacian <andrej@kacian.sk>
Tue, 1 Jul 2014 17:14:47 +0000 (19:14 +0200)
committerAndrej Kacian <andrej@kacian.sk>
Tue, 1 Jul 2014 17:46:43 +0000 (19:46 +0200)
src/plugins/rssyl/libfeed/date.c
src/plugins/rssyl/libfeed/feeditem.c
src/plugins/rssyl/libfeed/parser_atom10.c
src/plugins/rssyl/rssyl_add_item.c
src/plugins/rssyl/rssyl_update_comments.c
src/plugins/rssyl/rssyl_update_feed.c

index 2b8ffff5f6e3dac76a9a7f88d50605ed66fa93a5..c37756d44f72adef6b79922d49c2b192141671fa 100644 (file)
@@ -48,8 +48,9 @@ time_t parseISO8601Date(gchar *date) {
        time_t          t, t2, offset = 0;
        gboolean        success = FALSE;
        gchar *pos;
-       
-       g_assert(date != NULL);
+
+       if (date == NULL)
+               return -1;
        
        memset(&tm, 0, sizeof(struct tm));
        
index d04831b2adc8a011a0014f226ba124a11d4925ee..a85852ed3c93eb6420affaa834854a1af5c6c65f 100644 (file)
@@ -352,7 +352,10 @@ FeedItem *feed_item_copy(FeedItem *item)
        nitem->id_is_permalink = item->id_is_permalink;
        nitem->xhtml_content = item->xhtml_content;
 
-       nitem->data = g_memdup(item->data, sizeof(item->data));
+       /* We have no way of knowing the size of object item->data is pointing
+        * to, so we can not reliably copy it to the new item. Caller will have
+        * to take care of that itself. */
+       nitem->data = NULL;
 
        return nitem;
 }
index c04e77c1d9b9cad256622668525d06786b0c6db5..64a4ffeaadafd60a5a5154a48736d752b296227b 100644 (file)
@@ -51,6 +51,11 @@ void feed_parser_atom10_start(void *data, const gchar *el, const gchar **attr)
 
        } else if( ctx->depth == 2 ) {
 
+               /* This should only happen with malformed atom feeds - we're in
+                * XML depth 2, but not inside an <entry> block. */
+               if (ctx->curitem == NULL)
+                       return;
+
                if( !strcmp(el, "author") ) {
                        /* Start of author info for current feed item.
                         * Set correct location. */
index 1dc3e78ac3eb0ffc634262354ad3e17b858f7897..49f4a2395dad0b9666fb1412830c99fd4ffe1187 100644 (file)
@@ -373,11 +373,15 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
        dirname = folder_item_get_path(&ritem->item);
        template = g_strconcat(dirname, G_DIR_SEPARATOR_S,
                        RSSYL_TMP_TEMPLATE, NULL);
-       fd = mkstemp(template);
+       if ((fd = mkstemp(template)) < 0) {
+               g_warning("Couldn't mkstemp('%s'), not adding message!\n", template);
+               g_free(template);
+               return;
+       }
 
        f = fdopen(fd, "w");
-       if(f == NULL) {
-               g_warning("Couldn't open file '%s', not adding msg!\n", template);
+       if (f == NULL) {
+               g_warning("Couldn't open file '%s', not adding message!\n", template);
                g_free(template);
                return;
        }
index c54142da410d93fd076166909a0d8394492d5f5b..4b5cb332462110c1fef3caf8f8c5a59f0fb3393d 100644 (file)
@@ -85,6 +85,7 @@ void rssyl_update_comments(RFolderItem *ritem)
                        closedir(dp);
                        g_free(path);
                        debug_print("RSSyl: bailing out, app is exiting\n");
+                       return;
                }
 
                if( (num = to_number(d->d_name)) > 0 && d->d_type == DT_REG ) {
index 8a97f90f640ef097e5f7758aee91559af7c94bee..f7b4f542e1f66f912e0a850c2191bb1eb4a3299f 100644 (file)
@@ -61,7 +61,7 @@ static void *rssyl_fetch_feed_thr(void *arg)
 }
 
 /* rssyl_fetch_feed() */
-RFetchCtx *rssyl_fetch_feed(RFetchCtx *ctx, gboolean verbose)
+void rssyl_fetch_feed(RFetchCtx *ctx, gboolean verbose)
 {
 #ifdef USE_PTHREAD
        pthread_t pt;
@@ -127,13 +127,16 @@ RFetchCtx *rssyl_fetch_feed(RFetchCtx *ctx, gboolean verbose)
 
                ctx->success = FALSE;
        } else {
-               if( ctx->feed == NULL || feed_get_title(ctx->feed) == NULL ) {
+               if( feed_get_title(ctx->feed) == NULL ) {
                        /* libcurl was happy, but libfeed wasn't */
                        debug_print("RSSyl: Error reading feed\n");
                        if( verbose )
                                alertpanel_error(_("No valid feed found at\n<b>%s</b>"),
                                                        feed_get_url(ctx->feed));
-                       log_error(LOG_PROTOCOL, RSSYL_LOG_ERROR_NOFEED, ctx->feed->url);
+
+                       log_error(LOG_PROTOCOL, RSSYL_LOG_ERROR_NOFEED,
+                                       feed_get_url(ctx->feed));
+
                        ctx->success = FALSE;
                }
        }