]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pop3: Fix assert-crash when POP3 command name contained ':'
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 1 Dec 2022 10:37:17 +0000 (12:37 +0200)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Thu, 1 Dec 2022 13:13:49 +0000 (14:13 +0100)
The cmd_<name> reason code now only uses valid command names.

Broken by d2ab26be6038bd53b13a3ff18c403d6c192c1d91 with incomplete fix in
1309137812424c80e63d3c1052795b43d6e19803.

Fixes:
Panic: event_reason_code_prefix(): name has ':'

src/pop3/pop3-client.c
src/pop3/pop3-commands.c
src/pop3/pop3-commands.h

index 6a1b9be342731c45491a5fd0a435c61d5d742336..4bdbea283c4fb5bcde0e0e5ebd7a132b6e344b78 100644 (file)
@@ -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;
index e242ba9871778c36f42522698d163630601269fa..b0261e6369e84ff52f016d7f6ae358335c9a444d 100644 (file)
@@ -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);
 }
index 4b60725d94e909e381bf234cb9c9e3fefc7c2e02..37dd229cd020dd42710ece318699d2a8985f8996 100644 (file)
@@ -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