From: Timo Sirainen Date: Thu, 1 Dec 2022 10:37:17 +0000 (+0200) Subject: pop3: Fix assert-crash when POP3 command name contained ':' X-Git-Tag: 2.3.20~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=439321dd17d481b0ac40005ae7fc908d8c87fe42;p=thirdparty%2Fdovecot%2Fcore.git pop3: Fix assert-crash when POP3 command name contained ':' The cmd_ reason code now only uses valid command names. Broken by d2ab26be6038bd53b13a3ff18c403d6c192c1d91 with incomplete fix in 1309137812424c80e63d3c1052795b43d6e19803. Fixes: Panic: event_reason_code_prefix(): name has ':' --- diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index 6a1b9be342..4bdbea283c 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -742,15 +742,18 @@ bool client_handle_input(struct client *client) args = strchr(line, ' '); if (args != NULL) *args++ = '\0'; - if (*line == '\0') { - client_send_line(client, "-ERR Unknown command."); + + const struct pop3_command *cmd = pop3_command_find(line); + if (cmd == NULL) { + client_send_line(client, "-ERR Unknown command: %s", line); ret = -1; } else T_BEGIN { const char *reason_code = - event_reason_code_prefix("pop3", "cmd_", line); + event_reason_code_prefix("pop3", "cmd_", + cmd->name); struct event_reason *reason = event_reason_begin(reason_code); - ret = client_command_execute(client, line, + ret = client_command_execute(client, cmd, args != NULL ? args : ""); event_reason_end(&reason); } T_END; diff --git a/src/pop3/pop3-commands.c b/src/pop3/pop3-commands.c index e242ba9871..b0261e6369 100644 --- a/src/pop3/pop3-commands.c +++ b/src/pop3/pop3-commands.c @@ -948,14 +948,9 @@ const struct pop3_command *pop3_command_find(const char *name) } int client_command_execute(struct client *client, - const char *name, const char *args) + const struct pop3_command *cmd, const char *args) { while (*args == ' ') args++; - const struct pop3_command *cmd = pop3_command_find(name); - if (cmd != NULL) - return cmd->func(client, args); - - client_send_line(client, "-ERR Unknown command: %s", name); - return -1; + return cmd->func(client, args); } diff --git a/src/pop3/pop3-commands.h b/src/pop3/pop3-commands.h index 4b60725d94..37dd229cd0 100644 --- a/src/pop3/pop3-commands.h +++ b/src/pop3/pop3-commands.h @@ -8,6 +8,6 @@ struct pop3_command { const struct pop3_command *pop3_command_find(const char *name); int client_command_execute(struct client *client, - const char *name, const char *args); + const struct pop3_command *cmd, const char *args); #endif