summaryrefslogtreecommitdiffstats
path: root/imap
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2018-01-06 16:15:39 -0800
committerKevin McCarthy <kevin@8t8.us>2018-01-06 16:15:39 -0800
commite0229b8749bf67d42d6f35dfcc8cf7d7a4da3477 (patch)
treef78361a49ccb2ca08bc984afec80282f556694da /imap
parent2f510d6057f1af5b5297e47d7d91ad536d80d8b6 (diff)
parent8fcf8edaeff52e98cb61d75e06c3dd4a2ca19046 (diff)
Merge branch 'stable'
Diffstat (limited to 'imap')
-rw-r--r--imap/command.c41
-rw-r--r--imap/imap.c14
-rw-r--r--imap/imap_private.h4
-rw-r--r--imap/message.c18
-rw-r--r--imap/util.c5
5 files changed, 51 insertions, 31 deletions
diff --git a/imap/command.c b/imap/command.c
index 41b4bee6..1cff867b 100644
--- a/imap/command.c
+++ b/imap/command.c
@@ -33,6 +33,7 @@
#include <ctype.h>
#include <stdlib.h>
+#include <errno.h>
#define IMAP_CMD_BUFSIZE 512
@@ -511,7 +512,7 @@ static int cmd_handle_untagged (IMAP_DATA* idata)
dprint (2, (debugfile, "Handling EXISTS\n"));
/* new mail arrived */
- count = atoi (pn);
+ mutt_atoui (pn, &count);
if ( !(idata->reopen & IMAP_EXPUNGE_PENDING) &&
count < idata->max_msn)
@@ -629,8 +630,8 @@ static void cmd_parse_expunge (IMAP_DATA* idata, const char* s)
dprint (2, (debugfile, "Handling EXPUNGE\n"));
- exp_msn = atoi (s);
- if (exp_msn < 1 || exp_msn > idata->max_msn)
+ if (mutt_atoui (s, &exp_msn) < 0 ||
+ exp_msn < 1 || exp_msn > idata->max_msn)
return;
h = idata->msn_index[exp_msn - 1];
@@ -670,8 +671,8 @@ static void cmd_parse_fetch (IMAP_DATA* idata, char* s)
dprint (3, (debugfile, "Handling FETCH\n"));
- msn = atoi (s);
- if (msn < 1 || msn > idata->max_msn)
+ if (mutt_atoui (s, &msn) < 0 ||
+ msn < 1 || msn > idata->max_msn)
{
dprint (3, (debugfile, "FETCH response ignored for this message\n"));
return;
@@ -684,7 +685,7 @@ static void cmd_parse_fetch (IMAP_DATA* idata, char* s)
return;
}
- dprint (2, (debugfile, "Message UID %d updated\n", HEADER_DATA(h)->uid));
+ dprint (2, (debugfile, "Message UID %u updated\n", HEADER_DATA(h)->uid));
/* skip FETCH */
s = imap_next_word (s);
s = imap_next_word (s);
@@ -717,7 +718,11 @@ static void cmd_parse_fetch (IMAP_DATA* idata, char* s)
{
s += 3;
SKIPWS (s);
- uid = (unsigned int) atoi (s);
+ if (mutt_atoui (s, &uid) < 0)
+ {
+ dprint (2, (debugfile, "Illegal UID. Skipping update.\n"));
+ return;
+ }
if (uid != HEADER_DATA(h)->uid)
{
dprint (2, (debugfile, "FETCH UID vs MSN mismatch. Skipping update.\n"));
@@ -740,7 +745,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;
@@ -928,7 +933,8 @@ static void cmd_parse_search (IMAP_DATA* idata, const char* s)
while ((s = imap_next_word ((char*)s)) && *s != '\0')
{
- uid = (unsigned int)atoi (s);
+ if (mutt_atoui (s, &uid) < 0)
+ continue;
h = (HEADER *)int_hash_find (idata->uid_hash, uid);
if (h)
h->matched = 1;
@@ -943,10 +949,10 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
char* value;
BUFFY* inc;
IMAP_MBOX mx;
- int count;
+ unsigned int count;
IMAP_STATUS *status;
unsigned int olduv, oldun;
- long litlen;
+ unsigned int litlen;
short new = 0;
short new_msg_count = 0;
@@ -985,7 +991,14 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
while (*s && *s != ')')
{
value = imap_next_word (s);
- count = strtol (value, &value, 10);
+
+ errno = 0;
+ count = strtoul (value, &value, 10);
+ if (errno == ERANGE && count == ULONG_MAX)
+ {
+ dprint (1, (debugfile, "Error parsing STATUS number\n"));
+ return;
+ }
if (!ascii_strncmp ("MESSAGES", s, 8))
{
@@ -1005,7 +1018,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
if (*s && *s != ')')
s = imap_next_word (s);
}
- dprint (3, (debugfile, "%s (UIDVALIDITY: %d, UIDNEXT: %d) %d messages, %d recent, %d unseen\n",
+ dprint (3, (debugfile, "%s (UIDVALIDITY: %u, UIDNEXT: %u) %d messages, %d recent, %d unseen\n",
status->name, status->uidvalidity, status->uidnext,
status->messages, status->recent, status->unseen));
@@ -1044,7 +1057,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
if (value && !imap_mxcmp (mailbox, value))
{
- dprint (3, (debugfile, "Found %s in buffy list (OV: %d ON: %d U: %d)\n",
+ dprint (3, (debugfile, "Found %s in buffy list (OV: %u ON: %u U: %d)\n",
mailbox, olduv, oldun, status->unseen));
if (option(OPTMAILCHECKRECENT))
diff --git a/imap/imap.c b/imap/imap.c
index 309ac26c..668203b8 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;
@@ -266,7 +266,7 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
if (h->index == INT_MAX)
{
- dprint (2, (debugfile, "Expunging message UID %d.\n", HEADER_DATA (h)->uid));
+ dprint (2, (debugfile, "Expunging message UID %u.\n", HEADER_DATA (h)->uid));
h->active = 0;
idata->ctx->size -= h->content->length;
@@ -704,7 +704,8 @@ static int imap_open_mailbox (CONTEXT* ctx)
dprint (3, (debugfile, "Getting mailbox UIDVALIDITY\n"));
pc += 3;
pc = imap_next_word (pc);
- idata->uid_validity = strtol (pc, NULL, 10);
+ if (mutt_atoui (pc, &idata->uid_validity) < 0)
+ goto fail;
status->uidvalidity = idata->uid_validity;
}
else if (ascii_strncasecmp ("OK [UIDNEXT", pc, 11) == 0)
@@ -712,7 +713,8 @@ static int imap_open_mailbox (CONTEXT* ctx)
dprint (3, (debugfile, "Getting mailbox UIDNEXT\n"));
pc += 3;
pc = imap_next_word (pc);
- idata->uidnext = strtol (pc, NULL, 10);
+ if (mutt_atoui (pc, &idata->uidnext) < 0)
+ goto fail;
status->uidnext = idata->uidnext;
}
else
@@ -1751,7 +1753,7 @@ IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox, int create)
}
status->uidvalidity = *uidvalidity;
status->uidnext = uidnext ? *uidnext: 0;
- dprint (3, (debugfile, "mboxcache: hcache uidvalidity %d, uidnext %d\n",
+ dprint (3, (debugfile, "mboxcache: hcache uidvalidity %u, uidnext %u\n",
status->uidvalidity, status->uidnext));
}
mutt_hcache_free ((void **)&uidvalidity);
diff --git a/imap/imap_private.h b/imap/imap_private.h
index 8842add0..312fbfe4 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 28ff62b8..9ebfeb8e 100644
--- a/imap/message.c
+++ b/imap/message.c
@@ -529,9 +529,9 @@ 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;
- int uid;
+ unsigned int uid;
int cacheno;
IMAP_CACHE *cache;
int read;
@@ -618,7 +618,8 @@ int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
if (ascii_strncasecmp ("UID", pc, 3) == 0)
{
pc = imap_next_word (pc);
- uid = atoi (pc);
+ if (mutt_atoui (pc, &uid) < 0)
+ goto bail;
if (uid != HEADER_DATA(h)->uid)
mutt_error (_("The message index is incorrect. Try reopening the mailbox."));
}
@@ -1277,7 +1278,7 @@ char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s, int *server_changes)
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;
@@ -1288,7 +1289,8 @@ static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp)
/* skip to message number */
buf = imap_next_word (buf);
- h->data->msn = atoi (buf);
+ if (mutt_atoui (buf, &h->data->msn) < 0)
+ return rc;
/* find FETCH tag */
buf = imap_next_word (buf);
@@ -1360,7 +1362,8 @@ static int msg_parse_fetch (IMAP_HEADER *h, char *s)
{
s += 3;
SKIPWS (s);
- h->data->uid = (unsigned int) atoi (s);
+ if (mutt_atoui (s, &h->data->uid) < 0)
+ return -1;
s = imap_next_word (s);
}
@@ -1391,7 +1394,8 @@ static int msg_parse_fetch (IMAP_HEADER *h, char *s)
while (isdigit ((unsigned char) *s))
*ptmp++ = *s++;
*ptmp = 0;
- h->content_length = atoi (tmp);
+ if (mutt_atol (tmp, &h->content_length) < 0)
+ return -1;
}
else if (!ascii_strncasecmp ("BODY", s, 4) ||
!ascii_strncasecmp ("RFC822.HEADER", s, 13))
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;
}