commit 95a83c8220861185906df5b38eed589984847bfb
Author: Oswald Buddenhagen <[email protected]>
Date: Sun Feb 14 23:37:39 2021 +0100
be more tolerant of formally malformed response codes
fastmail sends flags containing ']' in PERMANENTFLAGS, which is formally
illegal. however, if we parse the embedded list before looking for the
response code's closing ']', things work out fine.
as a side effect we won't complain about similarly or completely
malformed response codes we don't recognize at all, which may or may not
be considered an improvement ...
src/drv_imap.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/src/drv_imap.c b/src/drv_imap.c
index 2ade80e..e6e4b26 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -1253,48 +1253,53 @@ parse_response_code( imap_store_t *ctx, imap_cmd_t
*cmd, char *s )
if (!s || *s != '[')
return RESP_OK; /* no response code */
s++;
- if (!(p = strchr( s, ']' ))) {
- bad_resp:
+ if (!(arg = next_arg( &s ))) {
error( "IMAP error: malformed response code\n" );
return RESP_CANCEL;
}
- *p++ = 0;
- if (!(arg = next_arg( &s )))
- goto bad_resp;
if (!strcmp( "UIDVALIDITY", arg )) {
if (!(arg = next_arg( &s )) ||
- (ctx->uidvalidity = strtoul( arg, &earg, 10 ), *earg))
+ (ctx->uidvalidity = strtoul( arg, &earg, 10 ), *earg !=
']'))
{
error( "IMAP error: malformed UIDVALIDITY status\n" );
return RESP_CANCEL;
}
} else if (!strcmp( "UIDNEXT", arg )) {
if (!(arg = next_arg( &s )) ||
- (ctx->uidnext = strtoul( arg, &earg, 10 ), *earg))
+ (ctx->uidnext = strtoul( arg, &earg, 10 ), *earg != ']'))
{
error( "IMAP error: malformed UIDNEXT status\n" );
return RESP_CANCEL;
}
} else if (!strcmp( "CAPABILITY", arg )) {
+ if (!(p = strchr( s, ']' ))) {
+ error( "IMAP error: malformed CAPABILITY status\n" );
+ return RESP_CANCEL;
+ }
+ *p = 0;
parse_capability( ctx, s );
- } else if (!strcmp( "ALERT", arg )) {
+ } else if (!strcmp( "ALERT]", arg )) {
/* RFC2060 says that these messages MUST be displayed
* to the user
*/
- for (; isspace( (uchar)*p ); p++);
- error( "*** IMAP ALERT *** %s\n", p );
+ if (!s) {
+ error( "IMAP error: malformed ALERT status\n" );
+ return RESP_CANCEL;
+ }
+ for (; isspace( (uchar)*s ); s++);
+ error( "*** IMAP ALERT *** %s\n", s );
} else if (cmd && !strcmp( "APPENDUID", arg )) {
if (!(arg = next_arg( &s )) ||
(ctx->uidvalidity = strtoul( arg, &earg, 10 ), *earg) ||
!(arg = next_arg( &s )) ||
- (((imap_cmd_out_uid_t *)cmd)->out_uid = strtoul( arg,
&earg, 10 ), *earg))
+ (((imap_cmd_out_uid_t *)cmd)->out_uid = strtoul( arg,
&earg, 10 ), *earg != ']'))
{
error( "IMAP error: malformed APPENDUID status\n" );
return RESP_CANCEL;
}
} else if (!strcmp( "PERMANENTFLAGS", arg )) {
parse_list_init( &ctx->parse_list_sts );
- if (parse_imap_list( NULL, &s, &ctx->parse_list_sts ) !=
LIST_OK) {
+ if (parse_imap_list( NULL, &s, &ctx->parse_list_sts ) !=
LIST_OK || *s != ']') {
error( "IMAP error: malformed PERMANENTFLAGS status\n"
);
return RESP_CANCEL;
}
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel