talons

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

commit 41eb0c5361b7412b434b9645b4c6602e51ee67cc
parent 33731b43ec12a30e76c3882a61c6370c66b64a67
Author: Colin Leroy <colin@colino.net>
Date:   Wed, 26 Nov 2008 08:13:21 +0000

2008-11-26 [colin]	3.6.1cvs43

	* src/imap.c
	* src/news.c
	* src/etpan/imap-thread.c
		Fix possible crashes due to clist_begin()
		not checking for NULLs (it should!)

Diffstat:
MChangeLog | 8++++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Msrc/etpan/imap-thread.c | 88++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/imap.c | 252+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/news.c | 76+++++++++++++++++++++++++++++++++++++++++-----------------------------------
6 files changed, 237 insertions(+), 190 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,11 @@ +2008-11-26 [colin] 3.6.1cvs43 + + * src/imap.c + * src/news.c + * src/etpan/imap-thread.c + Fix possible crashes due to clist_begin() + not checking for NULLs (it should!) + 2008-11-25 [colin] 3.6.1cvs42 * src/procmime.c diff --git a/PATCHSETS b/PATCHSETS @@ -3624,3 +3624,4 @@ ( cvs diff -u -r 1.382.2.486 -r 1.382.2.487 src/compose.c; cvs diff -u -r 1.49.2.120 -r 1.49.2.121 src/procmime.c; ) > 3.6.1cvs40.patchset ( cvs diff -u -r 1.382.2.487 -r 1.382.2.488 src/compose.c; ) > 3.6.1cvs41.patchset ( cvs diff -u -r 1.49.2.121 -r 1.49.2.122 src/procmime.c; ) > 3.6.1cvs42.patchset +( cvs diff -u -r 1.179.2.236 -r 1.179.2.237 src/imap.c; cvs diff -u -r 1.101.2.57 -r 1.101.2.58 src/news.c; cvs diff -u -r 1.1.4.105 -r 1.1.4.106 src/etpan/imap-thread.c; ) > 3.6.1cvs43.patchset diff --git a/configure.ac b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=6 MICRO_VERSION=1 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=42 +EXTRA_VERSION=43 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/etpan/imap-thread.c b/src/etpan/imap-thread.c @@ -1425,8 +1425,10 @@ int imap_threaded_select(Folder * folder, const char * mb, if (imap->imap_selection_info->sel_perm_flags) { GSList *t_flags = NULL; - clistiter *cur = - clist_begin(imap->imap_selection_info->sel_perm_flags); + clistiter *cur = NULL; + if (imap->imap_selection_info->sel_perm_flags) + cur = clist_begin(imap->imap_selection_info->sel_perm_flags); + for (; cur; cur = clist_next(cur)) { struct mailimap_flag_perm *flag = (struct mailimap_flag_perm *)clist_content(cur); if (flag->fl_type == MAILIMAP_FLAG_PERM_ALL) @@ -1768,7 +1770,7 @@ static int imap_get_msg_att_info(struct mailimap_msg_att * msg_att, static int result_to_uid_list(clist * fetch_result, carray ** result) { - clistiter * cur; + clistiter * cur = NULL; int r; int res; carray * tab; @@ -1779,8 +1781,10 @@ result_to_uid_list(clist * fetch_result, carray ** result) goto err; } - for(cur = clist_begin(fetch_result) ; cur != NULL ; - cur = clist_next(cur)) { + if (fetch_result) + cur = clist_begin(fetch_result); + + for(; cur != NULL ; cur = clist_next(cur)) { struct mailimap_msg_att * msg_att; uint32_t uid; uint32_t * puid; @@ -1968,7 +1972,7 @@ static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn, GSList static int result_to_uid_flags_list(clist * fetch_result, carray ** result) { - clistiter * cur; + clistiter * cur = NULL; int r; int res; carray * tab; @@ -1979,9 +1983,11 @@ result_to_uid_flags_list(clist * fetch_result, carray ** result) res = MAILIMAP_ERROR_MEMORY; goto err; } - - for(cur = clist_begin(fetch_result) ; cur != NULL ; - cur = clist_next(cur)) { + + if (fetch_result) + cur = clist_begin(fetch_result); + + for(; cur != NULL ; cur = clist_next(cur)) { struct mailimap_msg_att * msg_att; uint32_t uid; uint32_t * puid; @@ -2260,7 +2266,7 @@ static int imap_fetch(mailimap * imap, return r; } - if (clist_begin(fetch_result) == NULL) { + if (fetch_result == NULL || clist_begin(fetch_result) == NULL) { mailimap_fetch_list_free(fetch_result); return MAILIMAP_ERROR_FETCH; } @@ -2270,8 +2276,12 @@ static int imap_fetch(mailimap * imap, text = NULL; text_length = 0; - for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; - cur = clist_next(cur)) { + if (msg_att->att_list) + cur = clist_begin(msg_att->att_list); + else + cur = NULL; + + for(; cur != NULL ; cur = clist_next(cur)) { msg_att_item = clist_content(cur); if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { @@ -2362,7 +2372,7 @@ static int imap_fetch_header(mailimap * imap, return r; } - if (clist_begin(fetch_result) == NULL) { + if (fetch_result == NULL || clist_begin(fetch_result) == NULL) { mailimap_fetch_list_free(fetch_result); return MAILIMAP_ERROR_FETCH; } @@ -2372,8 +2382,12 @@ static int imap_fetch_header(mailimap * imap, text = NULL; text_length = 0; - for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; - cur = clist_next(cur)) { + if (msg_att->att_list) + cur = clist_begin(msg_att->att_list); + else + cur = NULL; + + for(; cur != NULL ; cur = clist_next(cur)) { msg_att_item = clist_content(cur); if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { @@ -2588,8 +2602,11 @@ static int imap_get_msg_att_info(struct mailimap_msg_att * msg_att, ref_size = 0; att_dyn = NULL; - for(item_cur = clist_begin(msg_att->att_list) ; item_cur != NULL ; - item_cur = clist_next(item_cur)) { + if (msg_att->att_list) + item_cur = clist_begin(msg_att->att_list); + else + item_cur = NULL; + for(; item_cur != NULL ; item_cur = clist_next(item_cur)) { struct mailimap_msg_att_item * item; item = clist_content(item_cur); @@ -2666,23 +2683,26 @@ imap_fetch_result_to_envelop_list(clist * fetch_result, i = 0; env_list = carray_new(16); - for(cur = clist_begin(fetch_result) ; cur != NULL ; - cur = clist_next(cur)) { - struct mailimap_msg_att * msg_att; - struct imap_fetch_env_info * env_info; - GSList *tags = NULL; - - msg_att = clist_content(cur); - - env_info = fetch_to_env_info(msg_att, &tags); - if (!env_info) - return MAILIMAP_ERROR_MEMORY; - carray_add(env_list, env_info, NULL); - carray_add(env_list, tags, NULL); + if (fetch_result) { + for(cur = clist_begin(fetch_result) ; cur != NULL ; + cur = clist_next(cur)) { + struct mailimap_msg_att * msg_att; + struct imap_fetch_env_info * env_info; + GSList *tags = NULL; + + msg_att = clist_content(cur); + + env_info = fetch_to_env_info(msg_att, &tags); + if (!env_info) + return MAILIMAP_ERROR_MEMORY; + carray_add(env_list, env_info, NULL); + carray_add(env_list, tags, NULL); + } + * p_env_list = env_list; + } else { + * p_env_list = NULL; } - - * p_env_list = env_list; - + return MAIL_NO_ERROR; } @@ -2784,7 +2804,7 @@ imap_get_envelopes_list(mailimap * imap, struct mailimap_set * set, return r; } - if (clist_begin(fetch_result) == NULL) { + if (fetch_result == NULL || clist_begin(fetch_result) == NULL) { res = MAILIMAP_ERROR_FETCH; debug_print("clist_begin = NULL\n"); goto err; diff --git a/src/imap.c b/src/imap.c @@ -786,7 +786,7 @@ static int imap_get_capabilities(IMAPSession *session) return result; } - if (capabilities == NULL) { + if (capabilities == NULL || capabilities->cap_list == NULL) { return MAILIMAP_NO_ERROR; } @@ -1698,6 +1698,9 @@ static GSList *flatten_mailimap_set(struct mailimap_set * set) int start, end, t; GSList *cur; + if (!set || !set->set_list) + return NULL; + for (list = clist_begin(set->set_list); list; list = clist_next(list)) { struct mailimap_set_item *item = (struct mailimap_set_item *)clist_content(list); start = item->set_first; @@ -3166,7 +3169,7 @@ static gchar imap_refresh_path_separator(IMAPSession *session, IMAPFolder *folde return '\0'; } - if (clist_count(lep_list) > 0) { + if (lep_list != NULL && clist_count(lep_list) > 0) { clistiter * iter = clist_begin(lep_list); struct mailimap_mailbox_list * mb; mb = clist_content(iter); @@ -3247,8 +3250,12 @@ static gint imap_set_message_flags(IMAPSession *session, for(cur = seq_list ; cur != NULL ; cur = g_slist_next(cur)) { struct mailimap_set * imapset = (struct mailimap_set *)cur->data; - struct mailimap_set_item *set_item = clist_content( - clist_begin(imapset->set_list)); + struct mailimap_set_item *set_item = NULL; + + if (imapset->set_list) + set_item = clist_content(clist_begin(imapset->set_list)); + else + continue; statusbar_progress_all(set_item->set_first, total, 1); @@ -3420,39 +3427,41 @@ static gint imap_status(IMAPSession *session, IMAPFolder *folder, } got_values = 0; - for(iter = clist_begin(data_status->st_info_list) ; iter != NULL ; - iter = clist_next(iter)) { - struct mailimap_status_info * info; - - info = clist_content(iter); - switch (info->st_att) { - case MAILIMAP_STATUS_ATT_MESSAGES: - if (messages) { - * messages = info->st_value; - got_values |= 1 << 0; - } - break; - - case MAILIMAP_STATUS_ATT_UIDNEXT: - if (uid_next) { - * uid_next = info->st_value; - got_values |= 1 << 2; - } - break; - - case MAILIMAP_STATUS_ATT_UIDVALIDITY: - if (uid_validity) { - * uid_validity = info->st_value; - got_values |= 1 << 3; - } - break; - - case MAILIMAP_STATUS_ATT_UNSEEN: - if (unseen) { - * unseen = info->st_value; - got_values |= 1 << 4; + if (data_status->st_info_list) { + for(iter = clist_begin(data_status->st_info_list) ; iter != NULL ; + iter = clist_next(iter)) { + struct mailimap_status_info * info; + + info = clist_content(iter); + switch (info->st_att) { + case MAILIMAP_STATUS_ATT_MESSAGES: + if (messages) { + * messages = info->st_value; + got_values |= 1 << 0; + } + break; + + case MAILIMAP_STATUS_ATT_UIDNEXT: + if (uid_next) { + * uid_next = info->st_value; + got_values |= 1 << 2; + } + break; + + case MAILIMAP_STATUS_ATT_UIDVALIDITY: + if (uid_validity) { + * uid_validity = info->st_value; + got_values |= 1 << 3; + } + break; + + case MAILIMAP_STATUS_ATT_UNSEEN: + if (unseen) { + * unseen = info->st_value; + got_values |= 1 << 4; + } + break; } - break; } } mailimap_mailbox_data_status_free(data_status); @@ -5014,19 +5023,20 @@ static int imap_flags_to_flags(struct mailimap_mbx_list_flags * imap_flags) } } - for(cur = clist_begin(imap_flags->mbf_oflags) ; cur != NULL ; - cur = clist_next(cur)) { - struct mailimap_mbx_list_oflag * oflag; - - oflag = clist_content(cur); - - switch (oflag->of_type) { - case MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS: - flags |= ETPAN_IMAP_MB_NOINFERIORS; - break; + if (imap_flags->mbf_oflags) { + for(cur = clist_begin(imap_flags->mbf_oflags) ; cur != NULL ; + cur = clist_next(cur)) { + struct mailimap_mbx_list_oflag * oflag; + + oflag = clist_content(cur); + + switch (oflag->of_type) { + case MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS: + flags |= ETPAN_IMAP_MB_NOINFERIORS; + break; + } } - } - + } return flags; } @@ -5036,74 +5046,75 @@ static GSList * imap_list_from_lep(IMAPFolder * folder, clistiter * iter; GSList * item_list = NULL, *llast = NULL; - for(iter = clist_begin(list) ; iter != NULL ; - iter = clist_next(iter)) { - struct mailimap_mailbox_list * mb; - int flags; - char delimiter; - char * name; - char * dup_name; - gchar * base; - gchar * loc_name; - gchar * loc_path; - FolderItem *new_item; - - mb = clist_content(iter); + if (list) { + for(iter = clist_begin(list) ; iter != NULL ; + iter = clist_next(iter)) { + struct mailimap_mailbox_list * mb; + int flags; + char delimiter; + char * name; + char * dup_name; + gchar * base; + gchar * loc_name; + gchar * loc_path; + FolderItem *new_item; + + mb = clist_content(iter); + + if (mb == NULL) + continue; - if (mb == NULL) - continue; + flags = 0; + if (mb->mb_flag != NULL) + flags = imap_flags_to_flags(mb->mb_flag); - flags = 0; - if (mb->mb_flag != NULL) - flags = imap_flags_to_flags(mb->mb_flag); - - delimiter = mb->mb_delimiter; - name = mb->mb_name; - - dup_name = strdup(name); - if (delimiter != '\0') - subst_char(dup_name, delimiter, '/'); - - base = g_path_get_basename(dup_name); - if (base[0] == '.') { - g_free(base); - free(dup_name); - continue; - } - if (!all && path_cmp(name, real_path) == 0) { + delimiter = mb->mb_delimiter; + name = mb->mb_name; + + dup_name = strdup(name); + if (delimiter != '\0') + subst_char(dup_name, delimiter, '/'); + + base = g_path_get_basename(dup_name); + if (base[0] == '.') { + g_free(base); + free(dup_name); + continue; + } + if (!all && path_cmp(name, real_path) == 0) { + g_free(base); + free(dup_name); + continue; + } + + if (!all && dup_name[strlen(dup_name)-1] == '/') { + dup_name[strlen(dup_name)-1] = '\0'; + } + + loc_name = imap_modified_utf7_to_utf8(base, FALSE); + loc_path = imap_modified_utf7_to_utf8(dup_name, FALSE); + + new_item = folder_item_new(FOLDER(folder), loc_name, loc_path); + if ((flags & ETPAN_IMAP_MB_NOINFERIORS) != 0) + new_item->no_sub = TRUE; + if (strcmp(dup_name, "INBOX") != 0 && + ((flags & ETPAN_IMAP_MB_NOSELECT) != 0)) + new_item->no_select = TRUE; + + if (item_list == NULL) + llast = item_list = g_slist_append(item_list, new_item); + else { + llast = g_slist_append(llast, new_item); + llast = llast->next; + } + debug_print("folder '%s' found.\n", loc_path); g_free(base); - free(dup_name); - continue; - } + g_free(loc_path); + g_free(loc_name); - if (!all && dup_name[strlen(dup_name)-1] == '/') { - dup_name[strlen(dup_name)-1] = '\0'; - } - - loc_name = imap_modified_utf7_to_utf8(base, FALSE); - loc_path = imap_modified_utf7_to_utf8(dup_name, FALSE); - - new_item = folder_item_new(FOLDER(folder), loc_name, loc_path); - if ((flags & ETPAN_IMAP_MB_NOINFERIORS) != 0) - new_item->no_sub = TRUE; - if (strcmp(dup_name, "INBOX") != 0 && - ((flags & ETPAN_IMAP_MB_NOSELECT) != 0)) - new_item->no_select = TRUE; - - if (item_list == NULL) - llast = item_list = g_slist_append(item_list, new_item); - else { - llast = g_slist_append(llast, new_item); - llast = llast->next; + free(dup_name); } - debug_print("folder '%s' found.\n", loc_path); - g_free(base); - g_free(loc_path); - g_free(loc_name); - - free(dup_name); - } - + } return item_list; } @@ -5196,15 +5207,16 @@ static GSList * imap_uid_list_from_lep(clist * list) result = NULL; - for(iter = clist_begin(list) ; iter != NULL ; - iter = clist_next(iter)) { - uint32_t * puid; - - puid = clist_content(iter); - result = g_slist_prepend(result, GINT_TO_POINTER(* puid)); - } - - result = g_slist_reverse(result); + if (list) { + for(iter = clist_begin(list) ; iter != NULL ; + iter = clist_next(iter)) { + uint32_t * puid; + + puid = clist_content(iter); + result = g_slist_prepend(result, GINT_TO_POINTER(* puid)); + } + result = g_slist_reverse(result); + } return result; } diff --git a/src/news.c b/src/news.c @@ -575,25 +575,26 @@ GSList *news_get_group_list(Folder *folder) return NULL; } - for (cur = clist_begin(grouplist); cur; cur = clist_next(cur)) { - struct newsnntp_group_info *info = (struct newsnntp_group_info *) - clist_content(cur); - if (fprintf(fp, "%s %d %d %c\n", - info->grp_name, - info->grp_last, - info->grp_first, - info->grp_type) < 0) { - log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n")); - session_destroy(SESSION(session)); - REMOTE_FOLDER(folder)->session = NULL; - fclose(fp); - g_free(filename); - newsnntp_list_free(grouplist); - return NULL; + if (grouplist) { + for (cur = clist_begin(grouplist); cur; cur = clist_next(cur)) { + struct newsnntp_group_info *info = (struct newsnntp_group_info *) + clist_content(cur); + if (fprintf(fp, "%s %d %d %c\n", + info->grp_name, + info->grp_last, + info->grp_first, + info->grp_type) < 0) { + log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n")); + session_destroy(SESSION(session)); + REMOTE_FOLDER(folder)->session = NULL; + fclose(fp); + g_free(filename); + newsnntp_list_free(grouplist); + return NULL; + } } + newsnntp_list_free(grouplist); } - newsnntp_list_free(grouplist); - if (fclose(fp) == EOF) { log_error(LOG_PROTOCOL, ("Can't write newsgroup list\n")); session_destroy(SESSION(session)); @@ -844,6 +845,9 @@ static gchar *news_parse_xhdr(clist *hdrlist, MsgInfo *msginfo) { struct newsnntp_xhdr_resp_item *hdr; + if (!hdrlist) + return NULL; + hdr = clist_content(clist_begin(hdrlist)); if (hdr->hdr_article != msginfo->msgnum) return NULL; @@ -1127,28 +1131,30 @@ static GSList *news_get_msginfos_for_range(NewsSession *session, FolderItem *ite return NULL; } - for (cur = clist_begin(msglist); cur; cur = clist_next(cur)) { - struct newsnntp_xover_resp_item *ritem = (struct newsnntp_xover_resp_item *)clist_content(cur); - msginfo = news_parse_xover(ritem); - - if (!msginfo) { - log_warning(LOG_PROTOCOL, _("invalid xover line\n")); - continue; - } + if (msglist) { + for (cur = clist_begin(msglist); cur; cur = clist_next(cur)) { + struct newsnntp_xover_resp_item *ritem = (struct newsnntp_xover_resp_item *)clist_content(cur); + msginfo = news_parse_xover(ritem); + + if (!msginfo) { + log_warning(LOG_PROTOCOL, _("invalid xover line\n")); + continue; + } - msginfo->folder = item; - news_set_msg_flags(item, msginfo); - msginfo->flags.tmp_flags |= MSG_NEWS; - msginfo->newsgroups = g_strdup(item->path); + msginfo->folder = item; + news_set_msg_flags(item, msginfo); + msginfo->flags.tmp_flags |= MSG_NEWS; + msginfo->newsgroups = g_strdup(item->path); - if (!newlist) - llast = newlist = g_slist_append(newlist, msginfo); - else { - llast = g_slist_append(llast, msginfo); - llast = llast->next; + if (!newlist) + llast = newlist = g_slist_append(newlist, msginfo); + else { + llast = g_slist_append(llast, msginfo); + llast = llast->next; + } } + newsnntp_xover_resp_list_free(msglist); } - newsnntp_xover_resp_list_free(msglist); news_folder_unlock(NEWS_FOLDER(item->folder));