talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 1fcddc03040d954d5fee040c8c2443d22e753416
parent 2267232d4cc846a901ddda2b1badd3e69a82d8e0
Author: Colin Leroy <colin@colino.net>
Date:   Sat,  7 Jun 2014 21:00:39 +0200

More coverity fixes

Diffstat:
Msrc/addressbook.c | 2+-
Msrc/crash.c | 2+-
Msrc/folderview.c | 4+++-
Msrc/jpilot.c | 33+++++++++++++++++----------------
Msrc/ldapquery.c | 10+++++++---
Msrc/ldapupdate.c | 10----------
Msrc/ldif.c | 2--
Msrc/main.c | 12+++++++++---
Msrc/mimeview.c | 3++-
Msrc/mutt.c | 2--
Msrc/partial_download.c | 6+++++-
Msrc/pine.c | 8+++-----
12 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/src/addressbook.c b/src/addressbook.c @@ -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; } diff --git a/src/crash.c b/src/crash.c @@ -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; } diff --git a/src/folderview.c b/src/folderview.c @@ -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; diff --git a/src/jpilot.c b/src/jpilot.c @@ -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 ) { diff --git a/src/ldapquery.c b/src/ldapquery.c @@ -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); diff --git a/src/ldapupdate.c b/src/ldapupdate.c @@ -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; diff --git a/src/ldif.c b/src/ldif.c @@ -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; } diff --git a/src/main.c b/src/main.c @@ -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 */ diff --git a/src/mimeview.c b/src/mimeview.c @@ -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); diff --git a/src/mutt.c b/src/mutt.c @@ -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; } diff --git a/src/partial_download.c b/src/partial_download.c @@ -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); diff --git a/src/pine.c b/src/pine.c @@ -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 );