Skip to content

Commit

Permalink
Fix control flow and T_BEGIN/T_END hygiene
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Phil Carmody committed Aug 31, 2016
1 parent b8f4e3a commit 14cac26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/director/login-connection.c
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/file-lock.c
Expand Up @@ -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)
Expand Down

0 comments on commit 14cac26

Please sign in to comment.