From: Brendan Cully Date: Thu, 10 Aug 2006 20:20:27 +0000 (+0000) Subject: Add type field for IMAP command data structure, check it before use. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b4fdd3c072d9b96c335db7c69d72a621c62ec72;p=neomutt Add type field for IMAP command data structure, check it before use. --- diff --git a/imap/browse.c b/imap/browse.c index 43463baf3..75355022e 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -112,6 +112,7 @@ int imap_browse (char* path, struct browser_state* state) { snprintf (buf, sizeof (buf), "%s \"\" \"%s\"", list_cmd, mbox); imap_cmd_start (idata, buf); + idata->cmdtype = IMAP_CT_LIST; idata->cmddata = &list; do { @@ -371,6 +372,7 @@ static int browse_add_list_result (IMAP_DATA* idata, const char* cmd, } imap_cmd_start (idata, cmd); + idata->cmdtype = IMAP_CT_LIST; idata->cmddata = &list; do { @@ -592,6 +594,7 @@ static int browse_verify_namespace (IMAP_DATA* idata, option (OPTIMAPLSUB) ? "LSUB" : "LIST", nsi->prefix); imap_cmd_start (idata, buf); + idata->cmdtype = IMAP_CT_LIST; idata->cmddata = &list; nsi->listable = 0; nsi->home_namespace = 0; diff --git a/imap/command.c b/imap/command.c index 69d164459..c6fb63e23 100644 --- a/imap/command.c +++ b/imap/command.c @@ -607,7 +607,7 @@ static void cmd_parse_list (IMAP_DATA* idata, char* s) char delimbuf[5]; /* worst case: "\\"\0 */ long litlen; - if (idata->cmddata) + if (idata->cmddata && idata->cmdtype == IMAP_CT_LIST) list = (IMAP_LIST*)idata->cmddata; else list = &lb; @@ -679,7 +679,7 @@ static void cmd_parse_lsub (IMAP_DATA* idata, char* s) ciss_url_t url; IMAP_LIST list; - if (idata->cmddata) + if (idata->cmddata && idata->cmdtype == IMAP_CT_LIST) { /* caller will handle response itself */ cmd_parse_list (idata, s); @@ -851,7 +851,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s) status->messages, status->recent, status->unseen)); /* caller is prepared to handle the result herself */ - if (idata->cmddata) + if (idata->cmddata && idata->cmdtype == IMAP_CT_STATUS) { memcpy (idata->cmddata, status, sizeof (IMAP_STATUS)); return; diff --git a/imap/imap.c b/imap/imap.c index 8688a21b4..cbec5cbfc 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1892,6 +1892,7 @@ int imap_complete(char* dest, size_t dlen, char* path) { /* and see what the results are */ strfcpy (completion, NONULL(mx.mbox), sizeof(completion)); + idata->cmdtype = IMAP_CT_LIST; idata->cmddata = &listresp; do { diff --git a/imap/imap_private.h b/imap/imap_private.h index ac97deaff..ecae3c346 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -180,6 +180,13 @@ typedef struct int state; } IMAP_COMMAND; +typedef enum +{ + IMAP_CT_NONE = 0, + IMAP_CT_LIST, + IMAP_CT_STATUS +} IMAP_COMMAND_TYPE; + typedef struct { /* This data is specific to a CONNECTION to an IMAP server */ @@ -200,8 +207,11 @@ typedef struct time_t lastread; /* last time we read a command for the server */ char* buf; unsigned int blen; - void* cmddata; /* if set, the response parser will store results for - * complicated commands here. */ + + /* if set, the response parser will store results for complicated commands + * here. */ + IMAP_COMMAND_TYPE cmdtype; + void* cmddata; /* command queue */ IMAP_COMMAND cmds[IMAP_PIPELINE_DEPTH];