]> granicus.if.org Git - mutt/commitdiff
Change imap literal counts to parse and store unsigned ints.
authorKevin McCarthy <kevin@8t8.us>
Sat, 6 Jan 2018 23:55:17 +0000 (15:55 -0800)
committerKevin McCarthy <kevin@8t8.us>
Sat, 6 Jan 2018 23:55:17 +0000 (15:55 -0800)
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.

imap/command.c
imap/imap.c
imap/imap_private.h
imap/message.c
imap/util.c

index 554aeb26d2b27964db3b55e57f4a2c5b766f737d..c607fcad225d01e54fda9b513b19430c13631bcd 100644 (file)
@@ -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;
 
index 8a089545e6c6bf9b1e5ffb9f95bc5e7c230e307c..ebdfbefc3eb47e67821f06c7a6a90de960cd18b1 100644 (file)
@@ -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;
index 0c28dfbbd67ac0269539cd69f08ebf19228771a9..b55c488f89b6af512ac372aad0a2d47f50410106 100644 (file)
@@ -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);
index 4caa29e448bc335c286917a0c9545592e0a0ee62..8bc387b5012251beda56c03ad6b0318ba915904d 100644 (file)
@@ -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;
 
index 2baa4f2c505deed6bd64de72e02bab2ee0ff2491..914c93c3c965bb12641e933b260baeb4cabbb933 100644 (file)
@@ -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;
 }