aboutsummaryrefslogtreecommitdiffstats
path: root/imap.c
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2010-08-28 19:14:13 +0200
committerMatthias Andree <matthias.andree@gmx.de>2010-08-28 19:15:43 +0200
commit019324f4b50349f9782ff013013d756c13c10d60 (patch)
tree606c1f21c74c7c4a9fec7c6a2f5a49093105d7ab /imap.c
parente798a9bfd0c70eabfd446fcee42cfa243b21f069 (diff)
downloadfetchmail-019324f4b50349f9782ff013013d756c13c10d60.tar.gz
fetchmail-019324f4b50349f9782ff013013d756c13c10d60.tar.bz2
fetchmail-019324f4b50349f9782ff013013d756c13c10d60.zip
Don't try to match trailing literals in sscanf,
but rather note how much input was consumed, stop short of the string, and use strncasecmp to match explicitly.
Diffstat (limited to 'imap.c')
-rw-r--r--imap.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/imap.c b/imap.c
index 93f37235..e22fea40 100644
--- a/imap.c
+++ b/imap.c
@@ -8,6 +8,7 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
+#include <strings.h>
#include <ctype.h>
#if defined(STDC_HEADERS)
#include <stdlib.h>
@@ -917,6 +918,7 @@ fetchflags:
while ((ok = imap_response(sock, buf)) == PS_UNTAGGED)
{
unsigned int num;
+ int consumed;
/* expected response format:
* IMAP< * 1 FETCH (FLAGS (\Seen))
@@ -926,7 +928,9 @@ fetchflags:
* IMAP< * 5 FETCH (UID 10 FLAGS (\Recent))
*/
if (unseen < count
- && sscanf(buf, "* %u FETCH ", &num) == 1
+ && sscanf(buf, "* %u %n", &num, &consumed) == 1
+ && 0 == strncasecmp(buf+consumed, "FETCH", 5)
+ && isspace((unsigned char)buf[consumed+5])
&& num >= 1 && num <= (unsigned)count
&& strstr(buf, "FLAGS ")
&& !strstr(buf, "\\SEEN")
@@ -1126,6 +1130,7 @@ static int imap_getpartialsizes(int sock, int first, int last, int *sizes)
{
unsigned int size;
int num;
+ int consumed;
char *ptr;
/* expected response formats:
@@ -1133,7 +1138,9 @@ static int imap_getpartialsizes(int sock, int first, int last, int *sizes)
* IMAP< * 1 FETCH (RFC822.SIZE 1187)
* IMAP< * 1 FETCH (UID 16 RFC822.SIZE 1447)
*/
- if (sscanf(buf, "* %d FETCH ", &num) == 1
+ if (sscanf(buf, "* %d %n", &num, &consumed) == 1
+ && 0 == strncasecmp(buf + consumed, "FETCH", 5)
+ && isspace((unsigned char)buf[consumed + 5])
&& (ptr = strstr(buf, "RFC822.SIZE "))
&& sscanf(ptr, "RFC822.SIZE %u", &size) == 1)
{
@@ -1209,16 +1216,20 @@ static int imap_fetch_headers(int sock, struct query *ctl,int number,int *lenp)
/* looking for FETCH response */
if ((ok = imap_response(sock, buf)) == PS_UNTAGGED)
{
+ int consumed;
/* expected response formats:
* IMAP> A0006 FETCH 1 RFC822.HEADER
* IMAP< * 1 FETCH (RFC822.HEADER {1360}
* IMAP< * 1 FETCH (UID 16 RFC822.HEADER {1360}
* IMAP< * 1 FETCH (UID 16 RFC822.SIZE 4029 RFC822.HEADER {1360}
*/
- if (sscanf(buf, "* %d FETCH ", &num) == 1
+ if (sscanf(buf, "* %d %n", &num, &consumed) == 1
+ && 0 == strncasecmp(buf + consumed, "FETCH", 5)
+ && isspace((unsigned char)buf[5+consumed])
&& num == number
- && (ptr = strstr(buf, "RFC822.HEADER "))
- && sscanf(ptr, "RFC822.HEADER {%d}", lenp) == 1)
+ && (ptr = strstr(buf, "RFC822.HEADER"))
+ && sscanf(ptr, "RFC822.HEADER {%d}%n", lenp, &consumed) == 1
+ && ptr[consumed-1] == '}')
{
return(PS_SUCCESS);
}