From: Kevin McCarthy Date: Sat, 6 Jan 2018 23:55:17 +0000 (-0800) Subject: Change imap literal counts to parse and store unsigned ints. X-Git-Tag: mutt-1-9-3-rel~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8fcf8edaeff52e98cb61d75e06c3dd4a2ca19046;p=mutt Change imap literal counts to parse and store unsigned ints. IMAP literals are of type number. Change imap_get_literal_count() to use mutt_atoui() instead of atoi(). Change the return type variables used to store the count to type unsigned int. It's doubtful this was a real issue, but as long as we're cleaning up incorrect atoi() usage, we should fix this too. --- diff --git a/imap/command.c b/imap/command.c index 554aeb26..c607fcad 100644 --- a/imap/command.c +++ b/imap/command.c @@ -729,7 +729,7 @@ static void cmd_parse_list (IMAP_DATA* idata, char* s) IMAP_LIST* list; IMAP_LIST lb; char delimbuf[5]; /* worst case: "\\"\0 */ - long litlen; + unsigned int litlen; if (idata->cmddata && idata->cmdtype == IMAP_CT_LIST) list = (IMAP_LIST*)idata->cmddata; @@ -936,7 +936,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s) unsigned int count; IMAP_STATUS *status; unsigned int olduv, oldun; - long litlen; + unsigned int litlen; short new = 0; short new_msg_count = 0; diff --git a/imap/imap.c b/imap/imap.c index 8a089545..ebdfbefc 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -199,9 +199,9 @@ void imap_logout_all (void) /* imap_read_literal: read bytes bytes from server into file. Not explicitly * buffered, relies on FILE buffering. NOTE: strips \r from \r\n. * Apparently even literals use \r\n-terminated strings ?! */ -int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes, progress_t* pbar) +int imap_read_literal (FILE* fp, IMAP_DATA* idata, unsigned int bytes, progress_t* pbar) { - long pos; + unsigned int pos; char c; int r = 0; diff --git a/imap/imap_private.h b/imap/imap_private.h index 0c28dfbb..b55c488f 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -246,7 +246,7 @@ int imap_exec_msgset (IMAP_DATA* idata, const char* pre, const char* post, int imap_open_connection (IMAP_DATA* idata); void imap_close_connection (IMAP_DATA* idata); IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags); -int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes, progress_t*); +int imap_read_literal (FILE* fp, IMAP_DATA* idata, unsigned int bytes, progress_t*); void imap_expunge_mailbox (IMAP_DATA* idata); void imap_logout (IMAP_DATA** idata); int imap_sync_message_for_copy (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd, @@ -294,7 +294,7 @@ char* imap_fix_path (IMAP_DATA* idata, const char* mailbox, char* path, size_t plen); void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest, size_t dlen); -int imap_get_literal_count (const char* buf, long* bytes); +int imap_get_literal_count (const char* buf, unsigned int* bytes); char* imap_get_qualifier (char* buf); int imap_mxcmp (const char* mx1, const char* mx2); char* imap_next_word (char* s); diff --git a/imap/message.c b/imap/message.c index 4caa29e4..8bc387b5 100644 --- a/imap/message.c +++ b/imap/message.c @@ -529,7 +529,7 @@ int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno) char buf[LONG_STRING]; char path[_POSIX_PATH_MAX]; char *pc; - long bytes; + unsigned int bytes; progress_t progressbar; unsigned int uid; int cacheno; @@ -1234,7 +1234,7 @@ char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s) static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp) { IMAP_DATA* idata; - long bytes; + unsigned int bytes; int rc = -1; /* default now is that string isn't FETCH response*/ int parse_rc; diff --git a/imap/util.c b/imap/util.c index 2baa4f2c..914c93c3 100644 --- a/imap/util.c +++ b/imap/util.c @@ -476,7 +476,7 @@ void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest, /* imap_get_literal_count: write number of bytes in an IMAP literal into * bytes, return 0 on success, -1 on failure. */ -int imap_get_literal_count(const char *buf, long *bytes) +int imap_get_literal_count(const char *buf, unsigned int *bytes) { char *pc; char *pn; @@ -489,7 +489,8 @@ int imap_get_literal_count(const char *buf, long *bytes) while (isdigit ((unsigned char) *pc)) pc++; *pc = 0; - *bytes = atoi(pn); + if (mutt_atoui (pn, bytes) < 0) + return -1; return 0; }