More coverity fixes
authorColin Leroy <colin@colino.net>
Sat, 7 Jun 2014 19:00:39 +0000 (21:00 +0200)
committerColin Leroy <colin@colino.net>
Sat, 7 Jun 2014 19:00:39 +0000 (21:00 +0200)
12 files changed:
src/addressbook.c
src/crash.c
src/folderview.c
src/jpilot.c
src/ldapquery.c
src/ldapupdate.c
src/ldif.c
src/main.c
src/mimeview.c
src/mutt.c
src/partial_download.c
src/pine.c

index ffd6909..4cbfc42 100644 (file)
@@ -3299,7 +3299,7 @@ static GtkCMCTreeNode *addressbook_find_group_node( GtkCMCTreeNode *parent, Item
                        AddressObject *obj;
 
                        obj = gtk_cmctree_node_get_row_data( GTK_CMCTREE(addrbook.ctree), node );
-                       if( obj->type == ADDR_ITEM_GROUP ) {
+                       if(obj && obj->type == ADDR_ITEM_GROUP ) {
                                ItemGroup *g = ADAPTER_GROUP(obj)->itemGroup;
                                if( g == group ) return node;
                        }
index d3c5022..279290a 100644 (file)
@@ -334,7 +334,7 @@ static void crash_debug(unsigned long crash_pid,
        pid_t pid;
 
        if (pipe(choutput) == -1) {
-               g_print("can't pipe - error %s", errno);
+               g_print("can't pipe - error %s", strerror(errno));
                return;
        }
 
index e9b0943..2ce7f9c 100644 (file)
@@ -892,6 +892,8 @@ static GtkCMCTreeNode *folderview_find_next_with_flag(GtkCMCTree *ctree,
 
        for (; node != NULL; node = gtkut_ctree_node_next(ctree, node)) {
                item = gtk_cmctree_node_get_row_data(ctree, node);
+               if (!item)
+                       continue;
                if (item->stype == F_TRASH || item->stype == F_DRAFT)
                        continue;
                switch (flag) {
@@ -1690,7 +1692,7 @@ static void set_special_folder(GtkCMCTree *ctree, FolderItem *item,
 
                                tmp = gtk_cmctree_node_get_row_data
                                        (ctree, sibling);
-                               if (tmp->stype != F_NORMAL)
+                               if (tmp && tmp->stype != F_NORMAL)
                                        sibling = GTK_CMCTREE_ROW(sibling)->sibling;
                                else
                                        break;
index 26f073e..a0ca9f3 100644 (file)
@@ -620,7 +620,10 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in
                return MGU_ERROR_READ;
        }
 
-       fseek(in, dbh.app_info_offset, SEEK_SET);
+       if (fseek(in, dbh.app_info_offset, SEEK_SET) < 0) {
+               fclose(in);
+               return MGU_ERROR_READ;
+       }
        *buf = ( char * ) malloc(rec_size);
        if (!(*buf)) {
                fclose(in);
@@ -692,7 +695,7 @@ static int read_header(FILE *pc_in, PC3RecordHeader *header) {
        }
        memcpy(packed_header, &l, sizeof(l));
        len=ntohl(l);
-       if (len > 255) {
+       if (len > 255 || len < sizeof(l)) {
                return -1;
        }
        num = fread(packed_header+sizeof(l), len-sizeof(l), 1, pc_in);
@@ -819,6 +822,8 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                        }
                        if( feof( in ) ) {
                                fclose( in );
+                               if (mem_rh)
+                                       free_mem_rec_header( &mem_rh );
                                return MGU_EOF;
                        }
                }
@@ -866,7 +871,10 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                                unique_id = mem_rh->unique_id;
                        }
                }
-               fseek( in, next_offset, SEEK_SET );
+               if (fseek( in, next_offset, SEEK_SET ) < 0) {
+                       fclose(in);
+                       return MGU_ERROR_READ;
+               }
                while( ! feof( in ) ) {
                        fpos = ftell( in );
                        if( out_of_order ) {
@@ -1048,7 +1056,7 @@ static void jpilot_parse_label( JPilotFile *pilotFile, gchar *labelEntry, ItemPe
 
        if( labelEntry ) {
                *buffer = '\0';
-               strcpy( buffer, labelEntry );
+               g_strlcpy( buffer, labelEntry, sizeof(buffer) );
                node = list = jpilot_parse_email( buffer );
                while( node ) {
                        email = addritem_create_item_email();
@@ -1201,17 +1209,10 @@ static void jpilot_load_address(
        }
 
        if( person->listEMail ) {
-               if( cat_id > -1 && cat_id < JPILOT_NUM_CATEG ) {
-                       /* Add to specified category */
-                       addrcache_folder_add_person(
-                               pilotFile->addressCache,
-                               folderInd[cat_id], person );
-               }
-               else {
-                       /* Add to root folder */
-                       addrcache_add_person(
-                               pilotFile->addressCache, person );
-               }
+               /* Add to specified category */
+               addrcache_folder_add_person(
+                       pilotFile->addressCache,
+                       folderInd[cat_id], person );
        }
        else {
                addritem_free_item_person( person );
@@ -1599,7 +1600,7 @@ gchar *jpilot_find_pilotdb( void ) {
        homedir = get_home_dir();
        if( ! homedir ) return g_strdup( "" );
 
-       strcpy( str, homedir );
+       g_strlcpy( str, homedir , sizeof(str));
        len = strlen( str );
        if( len > 0 ) {
                if( str[ len-1 ] != G_DIR_SEPARATOR ) {
index 2c504ab..ae2789d 100644 (file)
@@ -527,7 +527,7 @@ static GList *ldapqry_build_items_fl(
                if (attrib->name && strcmp(attrib->name, "jpegPhoto")) {
                        addritem_person_add_attribute( person, attrib );
                } else {
-                       if (qry && qry->server && qry->server->control) {
+                       if (qry->server && qry->server->control) {
                                gchar *dir = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, 
                                                        ADDRBOOK_DIR, G_DIR_SEPARATOR_S, NULL );
                                gchar *filename = g_strdup_printf("%s-%s-%s",
@@ -974,8 +974,12 @@ gint ldapqry_read_data_th( LdapQuery *qry ) {
                        qry->thread = g_malloc0( sizeof( pthread_t ) );
 
                        /* Setup thread */                      
-                       pthread_create( qry->thread, NULL,
-                               (void *) ldapqry_search, (void *) qry );
+                       if (pthread_create( qry->thread, NULL,
+                               (void *) ldapqry_search, (void *) qry ) != 0) {
+                               g_free(qry->thread);
+                               qry->thread = NULL;
+                               ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH;
+                       }
                }
        }
        return ADDRQUERY_RETVAL(qry);
index df12439..f304164 100644 (file)
@@ -403,11 +403,6 @@ Rdn *ldapsvr_modify_dn(GHashTable *hash, gchar *dn) {
                        update_rdn(rdn, compare, rest);
                        return rdn;
                }
-               else {
-                       /* We cannot remove dn */
-                       rdn_free(rdn);
-                       return NULL;
-               }
        }
        else {
                compare = g_hash_table_lookup(hash, rdn->attribute);
@@ -416,11 +411,6 @@ Rdn *ldapsvr_modify_dn(GHashTable *hash, gchar *dn) {
                        update_rdn(rdn, compare, rest);
                        return rdn;
                }
-               else {
-                       /* We cannot remove dn */
-                       rdn_free(rdn);
-                       return NULL;
-               }
        }
        rdn_free(rdn);
        return NULL;
index a34c40e..54d90aa 100644 (file)
@@ -167,8 +167,6 @@ void ldif_field_toggle( Ldif_FieldRec *rec ) {
 */
 static gint ldif_hash_free_vis( gpointer key, gpointer value, gpointer data ) {
        ldif_free_fieldrec( ( Ldif_FieldRec * ) value );
-       value = NULL;
-       key = NULL;
        return -1;
 }
 
index 0202a20..6d0a1c0 100644 (file)
@@ -1608,9 +1608,15 @@ static void exit_claws(MainWindow *mainwin)
        if(mainwin->folderview->opened) {
                FolderItem *item;
 
-               item = gtk_cmctree_node_get_row_data(GTK_CMCTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
-               summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
-               prefs_common.last_opened_folder = folder_item_get_identifier(item);
+               item = gtk_cmctree_node_get_row_data(
+                       GTK_CMCTREE(mainwin->folderview->ctree),
+                       mainwin->folderview->opened);
+               if (item) {
+                       summary_save_prefs_to_folderitem(
+                               mainwin->folderview->summaryview, item);
+                       prefs_common.last_opened_folder = 
+                               folder_item_get_identifier(item);
+               }
        }
 
        /* save all state before exiting */
index 8b20d5c..088ad29 100644 (file)
@@ -1710,8 +1710,9 @@ static void mimeview_drag_data_get(GtkWidget          *widget,
                                }
                                procheader_header_array_destroy(headers);
                        }
-                       fclose(fp);
                }
+               if (fp != NULL)
+                       fclose(fp);
                if (name)
                        filename = g_path_get_basename(name);
                g_free(name);
index 4e51af1..4564347 100644 (file)
@@ -64,8 +64,6 @@ void mutt_set_file( MuttFile* muttFile, const gchar *value ) {
  */
 static gint mutt_free_table_vis( gpointer key, gpointer value, gpointer data ) {
        g_free( key );
-       key = NULL;
-       value = NULL;
        return TRUE;
 }
 
index d7b0ce6..9a79faa 100644 (file)
@@ -316,7 +316,11 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        }
 
        fclose(fp);
-       rename_force(pathnew, filename);
+       if (rename_force(pathnew, filename) != 0) {
+               g_free(pathnew);
+               goto bail;
+       }
+
        g_free(pathnew);
        msginfo->planned_download = download;
        msgcache_update_msg(msginfo->folder->cache, msginfo);
index 355e636..5d29ee5 100644 (file)
@@ -66,8 +66,6 @@ void pine_set_file( PineFile* pineFile, const gchar *value ) {
  */
 static gint pine_free_table_vis( gpointer key, gpointer value, gpointer data ) {
        g_free( key );
-       key = NULL;
-       value = NULL;
        return TRUE;
 }
 
@@ -510,9 +508,9 @@ static void pine_build_items( PineFile *pineFile, AddressCache *cache, gchar *li
                        }
                }
                else {
-                       email = pine_insert_table(
-                                       pineFile, cache, rec->address,
-                                       rec->name, rec->comments );
+                       pine_insert_table(
+                               pineFile, cache, rec->address,
+                               rec->name, rec->comments );
                }
 
                pine_free_rec( rec );