From: Aki Tuomi Date: Tue, 30 Jun 2020 11:01:12 +0000 (+0300) Subject: pop3-login: Read command separately X-Git-Tag: 2.3.11.2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba9482dae39072a64e9d7b62e16dc1e57ad530e6;p=thirdparty%2Fdovecot%2Fcore.git pop3-login: Read command separately Simplifies next commit --- diff --git a/src/pop3-login/client.c b/src/pop3-login/client.c index 267b6240e1..cae6442046 100644 --- a/src/pop3-login/client.c +++ b/src/pop3-login/client.c @@ -140,20 +140,36 @@ static void pop3_client_input(struct client *client) client_unref(&client); } +static bool client_read_cmd_name(struct client *client, const char **cmd_r) +{ + const unsigned char *data; + size_t size, i; + if (i_stream_read_more(client->input, &data, &size) <= 0) + return FALSE; + for(i = 0; i < size; i++) { + if (data[i] == ' ' || + data[i] == '\r' || + data[i] == '\n') { + *cmd_r = t_str_ucase(t_strndup(data, i)); + i_stream_skip(client->input, i+1); + return TRUE; + } + } + return FALSE; +} + static bool pop3_client_input_next_cmd(struct client *client) { struct pop3_client *pop3_client = (struct pop3_client *)client; - char *line, *args; + const char *cmd, *args; + bool parsed; - if ((line = i_stream_next_line(client->input)) == NULL) + if (!client_read_cmd_name(client, &cmd)) + return FALSE; + if ((args = i_stream_next_line(client->input)) == NULL) return FALSE; - args = strchr(line, ' '); - if (args != NULL) - *args++ = '\0'; - - if (client_command_execute(pop3_client, line, - args != NULL ? args : "")) + if (client_command_execute(pop3_client, cmd, args)) client->bad_counter = 0; else if (++client->bad_counter >= CLIENT_MAX_BAD_COMMANDS) { client_send_reply(client, POP3_CMD_REPLY_ERROR,