talons

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

commit f5eb56464104b0c6d067c14092f7f359c565fbbb
parent fd779c80a57f905b228e6972881368e5777cc562
Author: Colin Leroy <colin@colino.net>
Date:   Fri,  6 Jun 2014 15:27:33 +0200

Coverity fixes

Diffstat:
Msrc/mainwindow.c | 2+-
Msrc/plugins/bogofilter/bogofilter.c | 12++++++------
Msrc/plugins/pgpcore/select-keys.c | 2+-
Msrc/plugins/pgpcore/sgpgme.c | 60++++++++++++++++++++++++++++++++++--------------------------
Msrc/plugins/pgpinline/pgpinline.c | 1+
Msrc/plugins/pgpmime/pgpmime.c | 2++
Msrc/procmime.c | 75++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Msrc/procmsg.c | 100++++++++++++++++++-------------------------------------------------------------
Msrc/procmsg.h | 2--
Msrc/summaryview.c | 2+-
Msrc/textview.c | 2+-
11 files changed, 123 insertions(+), 137 deletions(-)

diff --git 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 == 1; + return 1; return g_utf8_collate(tag_a, tag_b); } diff --git a/src/plugins/bogofilter/bogofilter.c b/src/plugins/bogofilter/bogofilter.c @@ -263,6 +263,8 @@ static void bogofilter_do_filter(BogoFilterData *data) data->new_hams = g_slist_prepend(data->new_hams, msginfo); } else { gchar **parts = NULL; + + buf[sizeof(buf - 1)] = '\0'; if (strchr(buf, '/')) { tmp = strrchr(buf, '/')+1; } else { @@ -284,7 +286,7 @@ static void bogofilter_do_filter(BogoFilterData *data) fclose (input); else if (!input && output) fclose (output); - else { + else if (input && output) { gchar tmpbuf[BUFFSIZE]; gboolean err = FALSE; const gchar *bogosity = *parts[1] == 'S' ? "Spam": @@ -742,6 +744,7 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam) gchar *file = NULL; const gchar *bogo_exec = (config.bogopath && *config.bogopath) ? config.bogopath:"bogofilter"; gint status = 0; + if (msginfo == NULL && msglist == NULL) { return -1; } @@ -771,10 +774,8 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam) g_free(file); if (message_callback != NULL) message_callback(NULL, 0, 0, FALSE); - return 0; } - } - if (msglist) { + } else if (msglist) { GSList *cur = msglist; MsgInfo *info; int total = g_slist_length(msglist); @@ -881,9 +882,8 @@ int bogofilter_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam) if (message_callback != NULL) message_callback(NULL, 0, 0, FALSE); - return 0; } - return -1; + return 0; } void bogofilter_save_config(void) diff --git a/src/plugins/pgpcore/select-keys.c b/src/plugins/pgpcore/select-keys.c @@ -128,7 +128,7 @@ gpgmegtk_recipient_selection (GSList *recp_names, SelectionResult *result, sk.proto = proto; gtk_cmclist_clear (sk.clist); key = fill_clist (&sk, sk.pattern, proto); - update_progress (&sk, 0, sk.pattern); + update_progress (&sk, 0, sk.pattern ? sk.pattern : "NULL"); if (!key) { gtk_widget_show_all (sk.window); gtk_main (); diff --git a/src/plugins/pgpcore/sgpgme.c b/src/plugins/pgpcore/sgpgme.c @@ -619,19 +619,23 @@ void sgpgme_init() #else ctype_locale = g_strdup(setlocale(LC_CTYPE, NULL)); #endif - debug_print("setting gpgme locale to: %s\n", ctype_locale ? ctype_locale : "NULL"); - if (strchr(ctype_locale, '.')) - *(strchr(ctype_locale, '.')) = '\0'; - else if (strchr(ctype_locale, '@')) - *(strchr(ctype_locale, '@')) = '\0'; - ctype_utf8_locale = g_strconcat(ctype_locale, ".UTF-8", NULL); - - debug_print("setting gpgme locale to UTF8: %s\n", ctype_utf8_locale ? ctype_utf8_locale : "NULL"); - gpgme_set_locale(NULL, LC_CTYPE, ctype_utf8_locale); - - debug_print("done\n"); - g_free(ctype_utf8_locale); - g_free(ctype_locale); + if (ctype_locale) { + debug_print("setting gpgme CTYPE locale to: %s\n", ctype_locale); + if (strchr(ctype_locale, '.')) + *(strchr(ctype_locale, '.')) = '\0'; + else if (strchr(ctype_locale, '@')) + *(strchr(ctype_locale, '@')) = '\0'; + ctype_utf8_locale = g_strconcat(ctype_locale, ".UTF-8", NULL); + + debug_print("setting gpgme locale to UTF8: %s\n", ctype_utf8_locale ? ctype_utf8_locale : "NULL"); + gpgme_set_locale(NULL, LC_CTYPE, ctype_utf8_locale); + + debug_print("done\n"); + g_free(ctype_utf8_locale); + g_free(ctype_locale); + } else { + debug_print("couldn't set gpgme CTYPE locale\n"); + } #endif #ifdef LC_MESSAGES debug_print("setting gpgme MESSAGES locale\n"); @@ -640,19 +644,23 @@ void sgpgme_init() #else messages_locale = g_strdup(setlocale(LC_MESSAGES, NULL)); #endif - debug_print("setting gpgme locale to: %s\n", messages_locale ? messages_locale : "NULL"); - if (strchr(messages_locale, '.')) - *(strchr(messages_locale, '.')) = '\0'; - else if (strchr(messages_locale, '@')) - *(strchr(messages_locale, '@')) = '\0'; - messages_utf8_locale = g_strconcat(messages_locale, ".UTF-8", NULL); - debug_print("setting gpgme locale to UTF8: %s\n", messages_utf8_locale ? messages_utf8_locale : "NULL"); - - gpgme_set_locale(NULL, LC_MESSAGES, messages_utf8_locale); - - debug_print("done\n"); - g_free(messages_utf8_locale); - g_free(messages_locale); + if (messages_locale) { + debug_print("setting gpgme MESSAGES locale to: %s\n", messages_locale); + if (strchr(messages_locale, '.')) + *(strchr(messages_locale, '.')) = '\0'; + else if (strchr(messages_locale, '@')) + *(strchr(messages_locale, '@')) = '\0'; + messages_utf8_locale = g_strconcat(messages_locale, ".UTF-8", NULL); + debug_print("setting gpgme locale to UTF8: %s\n", messages_utf8_locale ? messages_utf8_locale : "NULL"); + + gpgme_set_locale(NULL, LC_MESSAGES, messages_utf8_locale); + + debug_print("done\n"); + g_free(messages_utf8_locale); + g_free(messages_locale); + } else { + debug_print("couldn't set gpgme MESSAGES locale\n"); + } #endif if (!gpgme_get_engine_info(&engineInfo)) { while (engineInfo) { diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c @@ -730,6 +730,7 @@ static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) gpgme_data_release(gpgtext); g_free(textstr); gpgme_release(ctx); + g_free(enccontent); return FALSE; } diff --git a/src/plugins/pgpmime/pgpmime.c b/src/plugins/pgpmime/pgpmime.c @@ -581,6 +581,7 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account, const gchar *fr g_warning("sgpgme_data_release_and_get_mem failed"); privacy_set_error(_("Data signing failed, no contents.")); g_free(micalg); + g_free(sigcontent); return FALSE; } @@ -719,6 +720,7 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data) g_warning("sgpgme_data_release_and_get_mem failed"); privacy_set_error(_("Encryption failed, %s"), gpgme_strerror(err)); gpgme_release(ctx); + g_free(enccontent); return FALSE; } diff --git a/src/procmime.c b/src/procmime.c @@ -352,12 +352,18 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) if (mimeinfo->type == MIMETYPE_MULTIPART || mimeinfo->type == MIMETYPE_MESSAGE) return TRUE; + if (mimeinfo->data.filename == NULL) + return FALSE; + infp = procmime_fopen(mimeinfo->data.filename, "rb"); if (!infp) { perror("fopen"); return FALSE; } - fseek(infp, mimeinfo->offset, SEEK_SET); + if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) { + perror("fseek"); + return FALSE; + } outfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename); if (!outfp) { @@ -388,7 +394,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) Base64Decoder *decoder; gboolean got_error = FALSE; gboolean uncanonicalize = FALSE; - FILE *tmpfp = outfp; + FILE *tmpfp = NULL; gboolean null_bytes = FALSE; gboolean starting = TRUE; @@ -406,7 +412,8 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) #ifdef HAVE_FGETS_UNLOCKED flockfile(tmpfp); #endif - } + } else + tmpfp = outfp; decoder = base64_decoder_new(); while ((inlen = MIN(readend - ftell(infp), sizeof(buf))) > 0 && !err) { @@ -493,8 +500,12 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo) return FALSE; } - g_stat(tmpfilename, &statbuf); - if (mimeinfo->tmp && (mimeinfo->data.filename != NULL)) + if (g_stat(tmpfilename, &statbuf) < 0) { + FILE_OP_ERROR(tmpfilename, "stat"); + return FALSE; + } + + if (mimeinfo->tmp) claws_unlink(mimeinfo->data.filename); g_free(mimeinfo->data.filename); mimeinfo->data.filename = tmpfilename; @@ -551,7 +562,10 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding) #ifdef HAVE_FGETS_UNLOCKED flockfile(infp); #endif - + } else { + procmime_fclose(outfp); + g_warning("Unknown mimeinfo"); + return FALSE; } if (encoding == ENC_BASE64) { @@ -660,7 +674,10 @@ gboolean procmime_encode_content(MimeInfo *mimeinfo, EncodingType encoding) g_free(mimeinfo->data.mem); } - g_stat(tmpfilename, &statbuf); + if (g_stat(tmpfilename, &statbuf) < 0) { + FILE_OP_ERROR(tmpfilename, "stat"); + return FALSE; + } mimeinfo->content = MIMECONTENT_FILE; mimeinfo->data.filename = tmpfilename; mimeinfo->tmp = TRUE; @@ -1439,7 +1456,10 @@ static void procmime_parse_message_rfc822(MimeInfo *mimeinfo, gboolean short_sca FILE_OP_ERROR(mimeinfo->data.filename, "fopen"); return; } - fseek(fp, mimeinfo->offset, SEEK_SET); + if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) { + FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + return; + } procheader_get_header_fields(fp, hentry); if (hentry[0].body != NULL) { tmp = conv_unmime_header(hentry[0].body, NULL, FALSE); @@ -1616,7 +1636,7 @@ static void procmime_parse_multipart(MimeInfo *mimeinfo, gboolean short_scan) {"Disposition:", NULL, TRUE}, {NULL, NULL, FALSE}}; - gchar *p, *tmp; + gchar *tmp; gchar *boundary; gint boundary_len = 0, lastoffset = -1, i; gchar buf[BUFFSIZE]; @@ -1638,8 +1658,12 @@ static void procmime_parse_multipart(MimeInfo *mimeinfo, gboolean short_scan) return; } - fseek(fp, mimeinfo->offset, SEEK_SET); - while ((p = SC_FGETS(buf, sizeof(buf), fp)) != NULL && result == 0) { + if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) { + FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + return; + } + + while (SC_FGETS(buf, sizeof(buf), fp) != NULL && result == 0) { if (ftell(fp) - 1 > (mimeinfo->offset + mimeinfo->length)) break; @@ -1726,7 +1750,7 @@ static void parse_parameters(const gchar *parameters, GHashTable *table) value[0] = '\0'; value++; - while (value[0] == ' ') + while (value[0] != '\0' && value[0] == ' ') value++; down_attr = g_utf8_strdown(attribute, -1); @@ -1773,12 +1797,12 @@ static void parse_parameters(const gchar *parameters, GHashTable *table) while (down_attr[strlen(down_attr)-1] == ' ') down_attr[strlen(down_attr)-1] = '\0'; } - if (value) { - while (value[0] == ' ') - value++; - while (value[strlen(value)-1] == ' ') - value[strlen(value)-1] = '\0'; - } + + while (value[0] != '\0' && value[0] == ' ') + value++; + while (value[strlen(value)-1] == ' ') + value[strlen(value)-1] = '\0'; + if (down_attr && strrchr(down_attr, '*') != NULL) { gchar *tmpattr; @@ -2133,7 +2157,10 @@ static MimeInfo *procmime_scan_file_with_offset(const gchar *filename, int offse MimeInfo *mimeinfo; struct stat buf; - g_stat(filename, &buf); + if (g_stat(filename, &buf) < 0) { + FILE_OP_ERROR(filename, "stat"); + return NULL; + } mimeinfo = procmime_mimeinfo_new(); mimeinfo->content = MIMECONTENT_FILE; @@ -2459,7 +2486,10 @@ static gint procmime_write_message_rfc822(MimeInfo *mimeinfo, FILE *fp) FILE_OP_ERROR(mimeinfo->data.filename, "fopen"); return -1; } - fseek(infp, mimeinfo->offset, SEEK_SET); + if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) { + FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + return -1; + } while (SC_FGETS(buf, sizeof(buf), infp) == buf) { strcrchomp(buf); if (buf[0] == '\n' && buf[1] == '\0') @@ -2532,7 +2562,10 @@ static gint procmime_write_multipart(MimeInfo *mimeinfo, FILE *fp) FILE_OP_ERROR(mimeinfo->data.filename, "fopen"); return -1; } - fseek(infp, mimeinfo->offset, SEEK_SET); + if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) { + FILE_OP_ERROR(mimeinfo->data.filename, "fseek"); + return -1; + } while (SC_FGETS(buf, sizeof(buf), infp) == buf) { if (IS_BOUNDARY(buf, boundary, strlen(boundary))) break; diff --git a/src/procmsg.c b/src/procmsg.c @@ -890,7 +890,7 @@ parse_again: cur = cur->next; } - if (orig || g_slist_length(orig)) { + if (orig && g_slist_length(orig)) { if (!last_account && nothing_to_sort) { /* can't find an account for the rest of the list */ cur = orig; @@ -1123,8 +1123,14 @@ gint procmsg_remove_special_headers(const gchar *in, const gchar *out) break; } } - while (fgets(buf, sizeof(buf), fp) != NULL) - fputs(buf, outfp); + while (fgets(buf, sizeof(buf), fp) != NULL) { + if (fputs(buf, outfp) == EOF) { + FILE_OP_ERROR(out, "fputs"); + fclose(outfp); + fclose(fp); + return -1; + } + } fclose(outfp); fclose(fp); return 0; @@ -1185,80 +1191,6 @@ static gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file, } -void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline) -{ - static const gchar *def_cmd = "lpr %s"; - static guint id = 0; - gchar *prtmp; - FILE *tmpfp, *prfp; - gchar buf[1024]; - gchar *p; - int r; - - cm_return_if_fail(msginfo); - - if (procmime_msginfo_is_encrypted(msginfo)) - tmpfp = procmime_get_first_encrypted_text_content(msginfo); - else - tmpfp = procmime_get_first_text_content(msginfo); - if (tmpfp == NULL) { - g_warning("Can't get text part\n"); - return; - } - - prtmp = g_strdup_printf("%s%cprinttmp.%08x", - get_mime_tmp_dir(), G_DIR_SEPARATOR, id++); - - if ((prfp = g_fopen(prtmp, "wb")) == NULL) { - FILE_OP_ERROR(prtmp, "fopen"); - g_free(prtmp); - fclose(tmpfp); - return; - } - - if (msginfo->date) { r = fprintf(prfp, "Date: %s\n", msginfo->date); if (r < 0) goto fpferr; } - if (msginfo->from) { r = fprintf(prfp, "From: %s\n", msginfo->from); if (r < 0) goto fpferr; } - if (msginfo->to) { r = fprintf(prfp, "To: %s\n", msginfo->to); if (r < 0) goto fpferr; } - if (msginfo->cc) { r = fprintf(prfp, "Cc: %s\n", msginfo->cc); if (r < 0) goto fpferr; } - if (msginfo->newsgroups) { - r = fprintf(prfp, "Newsgroups: %s\n", msginfo->newsgroups); if (r < 0) goto fpferr; - } - if (msginfo->subject) { r = fprintf(prfp, "Subject: %s\n", msginfo->subject); if (r < 0) goto fpferr; } - if (fputc('\n', prfp) == EOF) goto fpferr; - - while (fgets(buf, sizeof(buf), tmpfp) != NULL) { - r = fputs(buf, prfp); - if (r == EOF) goto fpferr; - } - - fclose(prfp); - fclose(tmpfp); - - if (cmdline && (p = strchr(cmdline, '%')) && *(p + 1) == 's' && - !strchr(p + 2, '%')) - g_snprintf(buf, sizeof(buf) - 1, cmdline, prtmp); - else { - if (cmdline) - g_warning("Print command-line is invalid: '%s'\n", - cmdline); - g_snprintf(buf, sizeof(buf) - 1, def_cmd, prtmp); - } - - g_free(prtmp); - - g_strchomp(buf); - if (buf[strlen(buf) - 1] != '&') - strncat(buf, "&", sizeof(buf) - strlen(buf) - 1); - if (system(buf) == -1) - g_warning("system(%s) failed.", buf); - return; -fpferr: - FILE_OP_ERROR(prtmp, "fprintf/fputc/fputs"); - g_free(prtmp); - fclose(tmpfp); - fclose(prfp); -} - MsgInfo *procmsg_msginfo_new_ref(MsgInfo *msginfo) { msginfo->refcnt++; @@ -1690,6 +1622,14 @@ static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_ses } send_mail: filepos = ftell(fp); + if (filepos < 0) { + FILE_OP_ERROR(file, "ftell"); + if (errstr) { + if (*errstr) g_free(*errstr); + *errstr = g_strdup_printf(_("Couldn't open file %s."), file); + } + return -1; + } if (encrypt) { MimeInfo *mimeinfo; @@ -1802,7 +1742,11 @@ send_mail: mailval = -1; } - fseek(fp, filepos, SEEK_SET); + if (fseek(fp, filepos, SEEK_SET) < 0) { + FILE_OP_ERROR(file, "fseek"); + mailval = -1; + } + if (newsgroup_list && newsac && (mailval == 0)) { Folder *folder; gchar *tmp = NULL; diff --git a/src/procmsg.h b/src/procmsg.h @@ -334,8 +334,6 @@ gint procmsg_send_queue (FolderItem *queue, gboolean procmsg_queue_lock (gchar **errstr); void procmsg_queue_unlock (void); gboolean procmsg_queue_is_empty (FolderItem *queue); -void procmsg_print_message (MsgInfo *msginfo, - const gchar *cmdline); MsgInfo *procmsg_msginfo_new (); MsgInfo *procmsg_msginfo_new_ref (MsgInfo *msginfo); diff --git a/src/summaryview.c b/src/summaryview.c @@ -6185,7 +6185,7 @@ static gint summary_tag_cmp_list(gconstpointer a, gconstpointer b) return tag_b == NULL ? 0:1; if (tag_b == NULL) - return tag_a == NULL ? 0:1; + return 1; return g_utf8_collate(tag_a, tag_b); } diff --git a/src/textview.c b/src/textview.c @@ -2146,7 +2146,7 @@ static gint textview_tag_cmp_list(gconstpointer a, gconstpointer b) return tag_b == NULL ? 0:1; if (tag_b == NULL) - return tag_a == NULL ? 0:1; + return 1; return g_utf8_collate(tag_a, tag_b); }