(util_finish): Do not allow to switch to
a higher state in case of command failure. (util_do_command): Run the command only if it is allowed in the current state.
Showing
1 changed file
with
12 additions
and
2 deletions
... | @@ -410,7 +410,13 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) | ... | @@ -410,7 +410,13 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) |
410 | va_end (ap); | 410 | va_end (ap); |
411 | free (buf); | 411 | free (buf); |
412 | /* Reset the state. */ | 412 | /* Reset the state. */ |
413 | new_state = (rc == RESP_OK) ? command->success : command->failure; | 413 | if (rc == RESP_OK) |
414 | new_state = command->success; | ||
415 | else if (command->failure <= state) | ||
416 | new_state = command->failure; | ||
417 | else | ||
418 | new_state = STATE_NONE; | ||
419 | |||
414 | if (new_state != STATE_NONE) | 420 | if (new_state != STATE_NONE) |
415 | state = new_state; | 421 | state = new_state; |
416 | return status; | 422 | return status; |
... | @@ -553,8 +559,12 @@ util_do_command (char *prompt) | ... | @@ -553,8 +559,12 @@ util_do_command (char *prompt) |
553 | nullcommand.tag = tag; | 559 | nullcommand.tag = tag; |
554 | return util_finish (&nullcommand, RESP_BAD, "Invalid command"); | 560 | return util_finish (&nullcommand, RESP_BAD, "Invalid command"); |
555 | } | 561 | } |
556 | 562 | ||
557 | command->tag = tag; | 563 | command->tag = tag; |
564 | |||
565 | if (command->states && (command->states & state) == 0) | ||
566 | return util_finish (command, RESP_BAD, "Wrong state"); | ||
567 | |||
558 | len = strlen (sp); | 568 | len = strlen (sp); |
559 | if (len && sp[len - 1] == '\n') | 569 | if (len && sp[len - 1] == '\n') |
560 | sp[len - 1] = '\0'; | 570 | sp[len - 1] = '\0'; | ... | ... |
-
Please register or sign in to post a comment