From cf8bcfa094cca9216fed143ade374544f88e08ab Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Thu, 5 Jun 2014 22:37:12 +0200 Subject: [PATCH] More Coverity fixes --- src/imap.c | 44 ++++++++++++++++++++++++++------------------ src/importldif.c | 3 ++- src/main.c | 40 +++++++++++++++++++++++++++------------- src/mainwindow.c | 4 ++-- src/messageview.c | 5 +++-- 5 files changed, 60 insertions(+), 36 deletions(-) diff --git a/src/imap.c b/src/imap.c index 6813d9e53..887071979 100644 --- a/src/imap.c +++ b/src/imap.c @@ -1672,8 +1672,10 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list, return -1; } destdir = imap_get_real_path(session, IMAP_FOLDER(folder), dest->path, &ok); - if (is_fatal(ok)) + if (is_fatal(ok)) { + g_free(destdir); return -1; + } statusbar_print_all(_("Adding messages...")); total = g_slist_length(file_list); for (cur = file_list; cur != NULL; cur = cur->next) { @@ -1870,8 +1872,10 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest, destdir = imap_get_real_path(session, IMAP_FOLDER(folder), dest->path, &ok); - if (is_fatal(ok)) + if (is_fatal(ok)) { + g_free(destdir); return ok; + } seq_list = imap_get_lep_set_from_msglist(IMAP_FOLDER(folder), msglist); uid_hash = g_hash_table_new(g_direct_hash, g_direct_equal); @@ -2487,10 +2491,8 @@ static gint imap_do_remove_msgs(Folder *folder, FolderItem *dest, imap_scan_required(folder, dest); g_free(destdir); - if (ok == MAILIMAP_NO_ERROR) - return 0; - else - return -1; + + return 0; } static gint imap_remove_msgs(Folder *folder, FolderItem *dest, @@ -2566,8 +2568,10 @@ static gint imap_scan_tree_real(Folder *folder, gboolean subs_only) strtailchomp(root_folder, '/'); real_path = imap_get_real_path (session, IMAP_FOLDER(folder), root_folder, &r); - if (is_fatal(r)) + if (is_fatal(r)) { + g_free(real_path); return -1; + } debug_print("IMAP root directory: %s\n", real_path); /* check if root directory exist */ @@ -2872,6 +2876,7 @@ GList *imap_scan_subtree(Folder *folder, FolderItem *item, gboolean unsubs_only, if (r) { g_free(real_path); statusbar_pop_all(); + g_free(tmp); return NULL; } folder_item_destroy(cur_item); @@ -3228,6 +3233,7 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item, real_oldpath = imap_get_real_path(session, IMAP_FOLDER(folder), item->path, &ok); if (is_fatal(ok)) { + g_free(real_oldpath); return -1; } @@ -3244,8 +3250,10 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item, } separator = imap_get_path_separator(session, IMAP_FOLDER(folder), item->path, &ok); - if (is_fatal(ok)) + if (is_fatal(ok)) { + g_free(real_oldpath); return -1; + } if (strchr(item->path, G_DIR_SEPARATOR)) { dirpath = g_path_get_dirname(item->path); newpath = g_strconcat(dirpath, G_DIR_SEPARATOR_S, name, NULL); @@ -3342,9 +3350,10 @@ static gint imap_remove_folder_real(Folder *folder, FolderItem *item) return -1; } path = imap_get_real_path(session, IMAP_FOLDER(folder), item->path, &ok); - if (is_fatal(ok)) + if (is_fatal(ok)) { + g_free(path); return -1; - + } imap_threaded_subscribe(folder, path, FALSE); selected_folder = (session->mbox != NULL) && @@ -3626,15 +3635,12 @@ gchar imap_get_path_separator_for_item(FolderItem *item) if (!item) return '/'; folder = item->folder; - + if (!folder) return '/'; - + imap_folder = IMAP_FOLDER(folder); - - if (!imap_folder) - return '/'; - + debug_print("getting session..."); session = imap_session_get(FOLDER(folder)); result = imap_get_path_separator(session, imap_folder, item->path, &ok); @@ -3830,8 +3836,10 @@ static gint imap_select(IMAPSession *session, IMAPFolder *folder, session->expunge = 0; real_path = imap_get_real_path(session, folder, path, &ok); - if (is_fatal(ok)) - return ok; + if (is_fatal(ok)) { + g_free(real_path); + return ok; + } g_slist_free(IMAP_FOLDER_ITEM(item)->ok_flags); IMAP_FOLDER_ITEM(item)->ok_flags = NULL; ok = imap_cmd_select(session, real_path, diff --git a/src/importldif.c b/src/importldif.c index 3d2460c7e..e8db5b64f 100644 --- a/src/importldif.c +++ b/src/importldif.c @@ -336,7 +336,8 @@ static gboolean imp_ldif_field_list_toggle( gint y = event->y; gint row, col; - gtk_cmclist_get_selection_info( clist, x, y, &row, &col ); + if (!gtk_cmclist_get_selection_info( clist, x, y, &row, &col )) + return FALSE; if( col != FIELD_COL_SELECT ) return FALSE; if( row > impldif_dlg.rowCount ) return FALSE; diff --git a/src/main.c b/src/main.c index 37b26d5cc..0202a2070 100644 --- a/src/main.c +++ b/src/main.c @@ -2241,6 +2241,7 @@ static gint prohibit_duplicate_launch(void) ret = fd_open_unix(path); #if HAVE_FLOCK flock(lock_fd, LOCK_UN); + close(lock_fd); claws_unlink(socket_lock); g_free(socket_lock); #endif @@ -2340,7 +2341,8 @@ static gint prohibit_duplicate_launch(void) } fd_write_all(uxsock, ".\n", 2); for (;;) { - fd_gets(uxsock, buf, sizeof(buf)); + fd_gets(uxsock, buf, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (!strncmp(buf, ".\n", 2)) break; fputs(buf, stdout); } @@ -2350,7 +2352,8 @@ static gint prohibit_duplicate_launch(void) gchar buf[BUFSIZ]; fd_write(uxsock, "statistics\n", 11); for (;;) { - fd_gets(uxsock, buf, sizeof(buf)); + fd_gets(uxsock, buf, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (!strncmp(buf, ".\n", 2)) break; fputs(buf, stdout); } @@ -2369,7 +2372,8 @@ static gint prohibit_duplicate_launch(void) fd_write_all(uxsock, str, strlen(str)); g_free(str); for (;;) { - fd_gets(uxsock, buf, sizeof(buf)); + fd_gets(uxsock, buf, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (!strncmp(buf, ".\n", 2)) break; fputs(buf, stdout); } @@ -2378,7 +2382,8 @@ static gint prohibit_duplicate_launch(void) gchar buf[BUFSIZ]; fd_write_all(uxsock, "get_display\n", 12); memset(buf, 0, sizeof(buf)); - fd_gets(uxsock, buf, sizeof(buf)); + fd_gets(uxsock, buf, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (strcmp2(buf, x_display)) { g_print("Claws Mail is already running on display %s.\n", buf); @@ -2428,7 +2433,8 @@ static GPtrArray *get_folder_item_list(gint sock) GPtrArray *folders = NULL; for (;;) { - fd_gets(sock, buf, sizeof(buf)); + fd_gets(sock, buf, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (!strncmp(buf, ".\n", 2)) { break; } @@ -2456,7 +2462,11 @@ static void lock_socket_input_cb(gpointer data, gchar buf[BUFFSIZE]; sock = fd_accept(source); - fd_gets(sock, buf, sizeof(buf)); + if (sock < 0) + return; + + fd_gets(sock, buf, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (!strncmp(buf, "popup", 5)) { main_window_popup(mainwin); @@ -2478,7 +2488,8 @@ static void lock_socket_input_cb(gpointer data, gchar *mailto; mailto = g_strdup(buf + strlen("compose_attach") + 1); - while (fd_gets(sock, buf, sizeof(buf)) > 0) { + while (fd_gets(sock, buf, sizeof(buf) - 1) > 0) { + buf[sizeof(buf) - 1] = '\0'; strretchomp(buf); if (!strcmp2(buf, ".")) break; @@ -2594,8 +2605,9 @@ static void lock_socket_input_cb(gpointer data, folder_name = g_strdup(buf+7); strretchomp(folder_name); - if (fd_gets(sock, buf, sizeof(buf)) <= 0) + if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) goto search_exit; + buf[sizeof(buf) - 1] = '\0'; switch (toupper(buf[0])) { case 'S': searchType = ADVANCED_SEARCH_SUBJECT; break; @@ -2606,22 +2618,24 @@ static void lock_socket_input_cb(gpointer data, case 'E': searchType = ADVANCED_SEARCH_EXTENDED; break; } - if (fd_gets(sock, buf, sizeof(buf)) <= 0) + if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) goto search_exit; + buf[sizeof(buf) - 1] = '\0'; request = g_strdup(buf); strretchomp(request); recursive = TRUE; - if (fd_gets(sock, buf, sizeof(buf)) > 0) + if (fd_gets(sock, buf, sizeof(buf) - 1) > 0) recursive = buf[0] != '0'; + buf[sizeof(buf) - 1] = '\0'; + debug_print("search: %s %i %s %i\n", folder_name, searchType, request, recursive); - if (folder_name) - folderItem = folder_find_item_from_identifier(folder_name); + folderItem = folder_find_item_from_identifier(folder_name); - if (folder_name && folderItem == NULL) { + if (folderItem == NULL) { debug_print("Unknown folder item : '%s', searching folder\n",folder_name); Folder* folder = folder_find_from_path(folder_name); if (folder != NULL) diff --git a/src/mainwindow.c b/src/mainwindow.c index 62b380a40..46de25b6e 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -1241,7 +1241,7 @@ static gint mainwin_tag_cmp_list(gconstpointer a, gconstpointer b) return tag_b == NULL ? 0:1; if (tag_b == NULL) - return tag_a == NULL ? 0:1; + return tag_a == 1; return g_utf8_collate(tag_a, tag_b); } @@ -3301,7 +3301,7 @@ do { \ cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Sort/Descending", FALSE); } - if (mainwin->messageview + if (mainwin->messageview && mainwin->messageview->mimeview && mainwin->messageview->mimeview->textview) cm_toggle_menu_set_active_full(mainwin->ui_manager, "Menu/View/AllHeaders", diff --git a/src/messageview.c b/src/messageview.c index 2d9c6778f..3acacd274 100644 --- a/src/messageview.c +++ b/src/messageview.c @@ -1208,11 +1208,12 @@ static void messageview_register_nav(MessageView *messageview) } gboolean messageview_nav_has_prev(MessageView *messageview) { - return messageview->trail != NULL && messageview->trail_pos > 0; + return messageview != NULL && messageview->trail != NULL + && messageview->trail_pos > 0; } gboolean messageview_nav_has_next(MessageView *messageview) { - if (!messageview->trail) + if (!messageview || !messageview->trail) return FALSE; return sc_g_list_bigger(messageview->trail, messageview->trail_pos + 1); -- 2.25.1