]> granicus.if.org Git - neomutt/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)
committerRichard Russon <rich@flatcap.org>
Sun, 7 Jan 2018 01:51:21 +0000 (01:51 +0000)
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 d8ffbcaefce27c13848c9342b92b63f3f684f615..c13bf8416f088a0959ec73074e4039c3fc791123 100644 (file)
@@ -412,7 +412,7 @@ static void cmd_parse_list(struct ImapData *idata, char *s)
   struct ImapList *list = NULL;
   struct ImapList lb;
   char delimbuf[5]; /* worst case: "\\"\0 */
-  long litlen;
+  unsigned int litlen;
 
   if (idata->cmddata && idata->cmdtype == IMAP_CT_LIST)
     list = (struct ImapList *) idata->cmddata;
@@ -638,7 +638,7 @@ static void cmd_parse_status(struct ImapData *idata, char *s)
   unsigned int count;
   struct ImapStatus *status = NULL;
   unsigned int olduv, oldun;
-  long litlen;
+  unsigned int litlen;
   short new = 0;
   short new_msg_count = 0;
 
index 85f9e2c2cbd065c1ec44485294b2175a013f997e..85be54dcb179d9e7eacb9d2aa8918e24f439a519 100644 (file)
@@ -816,14 +816,15 @@ void imap_logout_all(void)
  * 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, struct ImapData *idata, long bytes, struct Progress *pbar)
+int imap_read_literal(FILE *fp, struct ImapData *idata, unsigned long bytes,
+                      struct Progress *pbar)
 {
   char c;
   bool r = false;
 
   mutt_debug(2, "reading %ld bytes\n", bytes);
 
-  for (long pos = 0; pos < bytes; pos++)
+  for (unsigned long pos = 0; pos < bytes; pos++)
   {
     if (mutt_socket_readchar(idata->conn, &c) != 1)
     {
index cc565cd89805d6ff4fca64bd1d60a0ad02a76232..11f4a4b0573668757468bd081a062bf94d9ae46b 100644 (file)
@@ -279,7 +279,7 @@ int imap_exec_msgset(struct ImapData *idata, const char *pre, const char *post,
 int imap_open_connection(struct ImapData *idata);
 void imap_close_connection(struct ImapData *idata);
 struct ImapData *imap_conn_find(const struct Account *account, int flags);
-int imap_read_literal(FILE *fp, struct ImapData *idata, long bytes, struct Progress *pbar);
+int imap_read_literal(FILE *fp, struct ImapData *idata, unsigned long bytes, struct Progress *pbar);
 void imap_expunge_mailbox(struct ImapData *idata);
 void imap_logout(struct ImapData **idata);
 int imap_sync_message_for_copy(struct ImapData *idata, struct Header *hdr, struct Buffer *cmd, int *err_continue);
@@ -324,7 +324,7 @@ struct ImapData *imap_new_idata(void);
 void imap_free_idata(struct ImapData **idata);
 char *imap_fix_path(struct ImapData *idata, const char *mailbox, char *path, size_t plen);
 void imap_cachepath(struct ImapData *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 a5823ee4c81a9b22e8958f00f10c5f2b3602c44d..8d69a3a50b057524d089a6b8ad3e5aa1f0953b09 100644 (file)
@@ -397,7 +397,7 @@ static int msg_parse_fetch(struct ImapHeader *h, char *s)
 static int msg_fetch_header(struct Context *ctx, struct ImapHeader *h, char *buf, FILE *fp)
 {
   struct ImapData *idata = NULL;
-  long bytes;
+  unsigned int bytes;
   int rc = -1; /* default now is that string isn't FETCH response */
   int parse_rc;
 
@@ -1006,7 +1006,7 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno)
   char buf[LONG_STRING];
   char path[_POSIX_PATH_MAX];
   char *pc = NULL;
-  long bytes;
+  unsigned int bytes;
   struct Progress progressbar;
   unsigned int uid;
   int cacheno;
index 12df02744ffd52ce43852480b59692cb13308d83..5e28d203606deb65bba6bf97affe541876900006 100644 (file)
@@ -737,7 +737,7 @@ void imap_cachepath(struct ImapData *idata, const char *mailbox, char *dest, siz
  * @retval  0 Success
  * @retval -1 Failure
  */
-int imap_get_literal_count(const char *buf, long *bytes)
+int imap_get_literal_count(const char *buf, unsigned int *bytes)
 {
   char *pc = NULL;
   char *pn = NULL;
@@ -750,7 +750,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;
 }