From 37cf691be418b60ea5e7577fe5e1301c703d2e15 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 25 Jan 2007 04:34:49 +0000 Subject: [PATCH] IMAP SEARCH - more internal validation to avoid crashing if we hit an invalid message pointer during a search operation. --- citadel/imap_search.c | 177 ++++++++++++++++++++++++---------------- citadel/serv_fulltext.c | 2 +- citadel/serv_imap.c | 14 ---- 3 files changed, 106 insertions(+), 87 deletions(-) diff --git a/citadel/imap_search.c b/citadel/imap_search.c index 750d5cd12..1a5baf25c 100644 --- a/citadel/imap_search.c +++ b/citadel/imap_search.c @@ -111,12 +111,14 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc"); - if (fieldptr != NULL) { - if (bmstrcasestr(fieldptr, itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc"); + if (fieldptr != NULL) { + if (bmstrcasestr(fieldptr, itemlist[pos+1])) { + match = 1; + } + free(fieldptr); } - free(fieldptr); } pos += 2; } @@ -126,10 +128,12 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (msg->cm_fields['T'] != NULL) { - if (imap_datecmp(itemlist[pos+1], - atol(msg->cm_fields['T'])) < 0) { - match = 1; + if (msg != NULL) { + if (msg->cm_fields['T'] != NULL) { + if (imap_datecmp(itemlist[pos+1], + atol(msg->cm_fields['T'])) < 0) { + match = 1; + } } } pos += 2; @@ -150,8 +154,10 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrcasestr(msg->cm_fields['M'], itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + if (bmstrcasestr(msg->cm_fields['M'], itemlist[pos+1])) { + match = 1; + } } } @@ -163,19 +169,21 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - fieldptr = msg->cm_fields['Y']; - if (fieldptr != NULL) { - if (bmstrcasestr(fieldptr, itemlist[pos+1])) { - match = 1; - } - } - else { - fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc"); + if (msg != NULL) { + fieldptr = msg->cm_fields['Y']; if (fieldptr != NULL) { if (bmstrcasestr(fieldptr, itemlist[pos+1])) { match = 1; } - free(fieldptr); + } + else { + fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc"); + if (fieldptr != NULL) { + if (bmstrcasestr(fieldptr, itemlist[pos+1])) { + match = 1; + } + free(fieldptr); + } } } pos += 2; @@ -207,11 +215,13 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrcasestr(msg->cm_fields['A'], itemlist[pos+1])) { - match = 1; - } - if (bmstrcasestr(msg->cm_fields['F'], itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + if (bmstrcasestr(msg->cm_fields['A'], itemlist[pos+1])) { + match = 1; + } + if (bmstrcasestr(msg->cm_fields['F'], itemlist[pos+1])) { + match = 1; + } } pos += 2; } @@ -228,29 +238,32 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, need_to_free_msg = 1; } - CC->redirect_buffer = malloc(SIZ); - CC->redirect_len = 0; - CC->redirect_alloc = SIZ; - CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1); - - fieldptr = rfc822_fetch_field(CC->redirect_buffer, itemlist[pos+1]); - if (fieldptr != NULL) { - if (bmstrcasestr(fieldptr, itemlist[pos+2])) { - match = 1; + if (msg != NULL) { + + CC->redirect_buffer = malloc(SIZ); + CC->redirect_len = 0; + CC->redirect_alloc = SIZ; + CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1); + + fieldptr = rfc822_fetch_field(CC->redirect_buffer, itemlist[pos+1]); + if (fieldptr != NULL) { + if (bmstrcasestr(fieldptr, itemlist[pos+2])) { + match = 1; + } + free(fieldptr); } - free(fieldptr); + + free(CC->redirect_buffer); + CC->redirect_buffer = NULL; + CC->redirect_len = 0; + CC->redirect_alloc = 0; } - free(CC->redirect_buffer); - CC->redirect_buffer = NULL; - CC->redirect_len = 0; - CC->redirect_alloc = 0; - pos += 3; /* Yes, three */ } else if (!strcasecmp(itemlist[pos], "KEYWORD")) { - /* FIXME */ + /* not implemented */ pos += 2; } @@ -259,8 +272,10 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (strlen(msg->cm_fields['M']) > atoi(itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + if (strlen(msg->cm_fields['M']) > atoi(itemlist[pos+1])) { + match = 1; + } } pos += 2; } @@ -284,10 +299,12 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (msg->cm_fields['T'] != NULL) { - if (imap_datecmp(itemlist[pos+1], - atol(msg->cm_fields['T'])) == 0) { - match = 1; + if (msg != NULL) { + if (msg->cm_fields['T'] != NULL) { + if (imap_datecmp(itemlist[pos+1], + atol(msg->cm_fields['T'])) == 0) { + match = 1; + } } } pos += 2; @@ -312,10 +329,12 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (msg->cm_fields['T'] != NULL) { - if (imap_datecmp(itemlist[pos+1], - atol(msg->cm_fields['T'])) < 0) { - match = 1; + if (msg != NULL) { + if (msg->cm_fields['T'] != NULL) { + if (imap_datecmp(itemlist[pos+1], + atol(msg->cm_fields['T'])) < 0) { + match = 1; + } } } pos += 2; @@ -326,10 +345,12 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (msg->cm_fields['T'] != NULL) { - if (imap_datecmp(itemlist[pos+1], - atol(msg->cm_fields['T'])) == 0) { - match = 1; + if (msg != NULL) { + if (msg->cm_fields['T'] != NULL) { + if (imap_datecmp(itemlist[pos+1], + atol(msg->cm_fields['T'])) == 0) { + match = 1; + } } } pos += 2; @@ -340,10 +361,12 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (msg->cm_fields['T'] != NULL) { - if (imap_datecmp(itemlist[pos+1], - atol(msg->cm_fields['T'])) >= 0) { - match = 1; + if (msg != NULL) { + if (msg->cm_fields['T'] != NULL) { + if (imap_datecmp(itemlist[pos+1], + atol(msg->cm_fields['T'])) >= 0) { + match = 1; + } } } pos += 2; @@ -354,10 +377,12 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (msg->cm_fields['T'] != NULL) { - if (imap_datecmp(itemlist[pos+1], - atol(msg->cm_fields['T'])) >= 0) { - match = 1; + if (msg != NULL) { + if (msg->cm_fields['T'] != NULL) { + if (imap_datecmp(itemlist[pos+1], + atol(msg->cm_fields['T'])) >= 0) { + match = 1; + } } } pos += 2; @@ -368,8 +393,10 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (strlen(msg->cm_fields['M']) < atoi(itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + if (strlen(msg->cm_fields['M']) < atoi(itemlist[pos+1])) { + match = 1; + } } pos += 2; } @@ -379,8 +406,10 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrcasestr(msg->cm_fields['U'], itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + if (bmstrcasestr(msg->cm_fields['U'], itemlist[pos+1])) { + match = 1; + } } pos += 2; } @@ -390,9 +419,11 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - for (i='A'; i<='Z'; ++i) { - if (bmstrcasestr(msg->cm_fields[i], itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + for (i='A'; i<='Z'; ++i) { + if (bmstrcasestr(msg->cm_fields[i], itemlist[pos+1])) { + match = 1; + } } } pos += 2; @@ -403,8 +434,10 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, msg = CtdlFetchMessage(IMAP->msgids[seq-1], 1); need_to_free_msg = 1; } - if (bmstrcasestr(msg->cm_fields['R'], itemlist[pos+1])) { - match = 1; + if (msg != NULL) { + if (bmstrcasestr(msg->cm_fields['R'], itemlist[pos+1])) { + match = 1; + } } pos += 2; } diff --git a/citadel/serv_fulltext.c b/citadel/serv_fulltext.c index cf28dce18..0626a77b0 100644 --- a/citadel/serv_fulltext.c +++ b/citadel/serv_fulltext.c @@ -277,7 +277,7 @@ void do_fulltext_indexing(void) { /* Here it is ... do each message! */ for (i=0; i 10) { + if (time(NULL) != last_progress) { lprintf(CTDL_DEBUG, "Indexed %d of %d messages (%d%%)\n", i, ft_num_msgs, diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index d750168ec..ebea96c20 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -1647,19 +1647,6 @@ void imap_command_loop(void) } - - -/* temporary function to insert a bogus pointer in the lobbie */ - -void cmd_bgus(char *argbuf) -{ - long bogus = 9999999; - CtdlSaveMsgPointersInRoom("Lobby", &bogus, 1, 0, NULL); - cprintf("%d bogus\n", CIT_OK); -} - - - /* * This function is called to register the IMAP extension with Citadel. */ @@ -1672,6 +1659,5 @@ char *serv_imap_init(void) NULL, imaps_greeting, imap_command_loop, NULL); #endif CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP); - CtdlRegisterProtoHook(cmd_bgus, "BGUS", "bogus"); return "$Id$"; } -- 2.39.2