]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Fix control flow and T_BEGIN/T_END hygiene
authorPhil Carmody <phil@dovecot.fi>
Wed, 31 Aug 2016 17:14:41 +0000 (20:14 +0300)
committerPhil Carmody <phil@dovecot.fi>
Wed, 31 Aug 2016 17:14:41 +0000 (20:14 +0300)
You mustn't goto, break, continue, or return from out of a
T_BEGIN {...} T_END block, as that will lose a t_pop().
This has been seen in the wild: Panic: Leaked t_pop() call

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/director/login-connection.c
src/lib/file-lock.c

index f6b7459d215114ee1b52599d3990ed9c40734d87..5db690aa87a8fa227355884496dc3f5ae3610e6d 100644 (file)
@@ -73,21 +73,27 @@ static void login_connection_input(struct login_connection *conn)
 
 static void login_connection_authreply_input(struct login_connection *conn)
 {
+       bool bail = FALSE;
        const char *line;
 
-       while ((line = i_stream_read_next_line(conn->input)) != NULL) T_BEGIN {
+       while (!bail && (line = i_stream_read_next_line(conn->input)) != NULL) T_BEGIN {
                if (!conn->handshaked) {
                        if (!version_string_verify(line, "director-authreply-client",
                                                   AUTHREPLY_PROTOCOL_MAJOR_VERSION)) {
                                i_error("authreply client sent invalid handshake: %s", line);
                                login_connection_deinit(&conn);
-                               return;
+                               bail = TRUE; /* don't return from within a T_BEGIN {...} T_END */
+                       } else {
+                               conn->handshaked = TRUE;
                        }
-                       conn->handshaked = TRUE;
                } else {
                        auth_input_line(line, conn);
                }
        } T_END;
+
+       if (bail)
+               return;
+
        if (conn->input->eof) {
                if (conn->input->stream_errno != 0 &&
                    conn->input->stream_errno != ECONNRESET) {
index 05515b50233a5b1ea66ad68be548bf3464bd9ce8..fd2a430660be54ac1c71c333ca7ac939c031aa63 100644 (file)
@@ -114,9 +114,9 @@ file_lock_find_proc_locks(int lock_fd ATTR_UNUSED)
 
                /* number: FLOCK/POSIX ADVISORY READ/WRITE pid
                   major:minor:inode region-start region-end */
-               if (str_array_length(args) < 8)
-                       continue;
-               if (strcmp(args[5], node_buf) == 0) {
+               if (str_array_length(args) < 8) {
+                       ; /* don't continue from within a T_BEGIN {...} T_END */
+               } else if (strcmp(args[5], node_buf) == 0) {
                        lock_type = strcmp(args[3], "READ") == 0 ?
                                "READ" : "WRITE";
                        if (str_to_pid(args[4], &pid) < 0)