]> 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)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 1 Dec 2022 10:40:02 +0000 (12:40 +0200)
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 1aa632d6378e004f4dba876e4f6d3b50200b1085..edb8727e6166885699f34037cd96268cda967c50 100644 (file)
@@ -750,15 +750,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 8162a9f1849558c8869e99c4a8df45d573831c97..8682633f967ca40c905aa2cff829bd73b7ddc6ec 100644 (file)
@@ -956,14 +956,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