From 828edf966ee46f65ec5d907f310cab270e7e1088 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 13 Jul 2008 19:08:13 +0300 Subject: [PATCH] SORT: Return BAD if sort program ends with REVERSE. --HG-- branch : HEAD --- src/imap/cmd-sort.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/imap/cmd-sort.c b/src/imap/cmd-sort.c index b49eaec921..93756e09d9 100644 --- a/src/imap/cmd-sort.c +++ b/src/imap/cmd-sort.c @@ -30,7 +30,7 @@ get_sort_program(struct client_command_context *cmd, { enum mail_sort_type mask = 0; unsigned int i, pos; - bool reverse; + bool reverse, last_reverse; if (args->type == IMAP_ARG_EOL) { /* empyty list */ @@ -38,12 +38,13 @@ get_sort_program(struct client_command_context *cmd, return -1; } - pos = 0; reverse = FALSE; + pos = 0; reverse = last_reverse = FALSE; for (; args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING; args++) { const char *arg = IMAP_ARG_STR(args); - if (strcasecmp(arg, "reverse") == 0) { + last_reverse = strcasecmp(arg, "reverse") == 0; + if (last_reverse) { reverse = !reverse; continue; } @@ -70,7 +71,10 @@ get_sort_program(struct client_command_context *cmd, (reverse ? MAIL_SORT_FLAG_REVERSE : 0); reverse = FALSE; } - + if (last_reverse) { + client_send_command_error(cmd, "Sort list ends with REVERSE."); + return -1; + } program[pos++] = MAIL_SORT_END; if (args->type != IMAP_ARG_EOL) { -- 2.47.3