dovecot-1.2: imap: Fixed parsing SELECT QRESYNC parameters

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 23 17:38:30 EEST 2010


details:   http://hg.dovecot.org/dovecot-1.2/rev/7e959d397a35
changeset: 9605:7e959d397a35
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 23 15:38:26 2010 +0100
description:
imap: Fixed parsing SELECT QRESYNC parameters

diffstat:

 src/imap/cmd-select.c |  38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)

diffs (91 lines):

diff -r cf0da2cd31fb -r 7e959d397a35 src/imap/cmd-select.c
--- a/src/imap/cmd-select.c	Fri Aug 20 20:38:26 2010 +0100
+++ b/src/imap/cmd-select.c	Mon Aug 23 15:38:26 2010 +0100
@@ -70,7 +70,7 @@
 		     const struct imap_arg *args)
 {
 	ARRAY_TYPE(seq_range) seqset, uidset;
-	unsigned int count;
+	const struct imap_arg *subargs;
 
 	if ((ctx->cmd->client->enabled_features &
 	     MAILBOX_FEATURE_QRESYNC) == 0) {
@@ -83,13 +83,8 @@
 		return FALSE;
 	}
 	args = IMAP_ARG_LIST_ARGS(args);
-	for (count = 0; args[count].type != IMAP_ARG_EOL; count++) ;
-
-	if (count < 2 || count > 4 ||
-	    args[0].type != IMAP_ARG_ATOM ||
-	    args[1].type != IMAP_ARG_ATOM ||
-	    (count > 2 && args[2].type != IMAP_ARG_ATOM) ||
-	    (count > 3 && args[3].type != IMAP_ARG_LIST)) {
+	if (args[0].type != IMAP_ARG_ATOM ||
+	    args[1].type != IMAP_ARG_ATOM) {
 		client_send_command_error(ctx->cmd,
 					  "Invalid QRESYNC parameters");
 		return FALSE;
@@ -98,37 +93,40 @@
 		strtoul(IMAP_ARG_STR_NONULL(&args[0]), NULL, 10);
 	ctx->qresync_modseq =
 		strtoull(IMAP_ARG_STR_NONULL(&args[1]), NULL, 10);
-	if (count > 2) {
+	args += 2;
+
+	if (args->type == IMAP_ARG_ATOM) {
 		i_array_init(&ctx->qresync_known_uids, 64);
-		if (imap_seq_set_parse(IMAP_ARG_STR_NONULL(&args[2]),
+		if (imap_seq_set_parse(IMAP_ARG_STR_NONULL(args),
 				       &ctx->qresync_known_uids) < 0) {
 			client_send_command_error(ctx->cmd,
 						  "Invalid QRESYNC known-uids");
 			return FALSE;
 		}
+		args++;
 	} else {
 		i_array_init(&ctx->qresync_known_uids, 64);
 		seq_range_array_add_range(&ctx->qresync_known_uids,
 					  1, (uint32_t)-1);
 	}
-	if (count > 3) {
-		args = IMAP_ARG_LIST_ARGS(&args[3]);
-		if (args[0].type != IMAP_ARG_ATOM ||
-		    args[1].type != IMAP_ARG_ATOM ||
-		    args[2].type != IMAP_ARG_EOL) {
+	if (args->type == IMAP_ARG_LIST) {
+		subargs = IMAP_ARG_LIST_ARGS(args);
+		if (subargs[0].type != IMAP_ARG_ATOM ||
+		    subargs[1].type != IMAP_ARG_ATOM ||
+		    subargs[2].type != IMAP_ARG_EOL) {
 			client_send_command_error(ctx->cmd,
 				"Invalid QRESYNC known set parameters");
 			return FALSE;
 		}
 		t_array_init(&seqset, 32);
-		if (imap_seq_set_parse(IMAP_ARG_STR_NONULL(&args[0]),
+		if (imap_seq_set_parse(IMAP_ARG_STR_NONULL(&subargs[0]),
 				       &seqset) < 0) {
 			client_send_command_error(ctx->cmd,
 				"Invalid QRESYNC known-sequence-set");
 			return FALSE;
 		}
 		t_array_init(&uidset, 32);
-		if (imap_seq_set_parse(IMAP_ARG_STR_NONULL(&args[1]),
+		if (imap_seq_set_parse(IMAP_ARG_STR_NONULL(&subargs[1]),
 				       &uidset) < 0) {
 			client_send_command_error(ctx->cmd,
 				"Invalid QRESYNC known-uid-set");
@@ -139,6 +137,12 @@
 				"Invalid QRESYNC sets");
 			return FALSE;
 		}
+		args++;
+	}
+	if (args->type != IMAP_ARG_EOL) {
+		client_send_command_error(ctx->cmd,
+					  "Invalid QRESYNC parameters");
+		return FALSE;
 	}
 	return TRUE;
 }


More information about the dovecot-cvs mailing list