Skip to content

Commit dee6828

Browse files
committed
sudo_logsrvd: Don't close relay connection before ExitMessage written
When we are relaying a connection with no I/O logs we need to be careful not to close the connection too early when relaying. In this case, handle_exit() sets the state to FINISHED but the last ClientMessage may not have been written yet.
1 parent e1829a1 commit dee6828

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

logsrvd/logsrvd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ client_msg_cb(int fd, int what, void *v)
11981198
buf->len -= buf->off;
11991199
buf->off = 0;
12001200

1201-
if (closure->state == FINISHED)
1201+
if (closure->state == FINISHED && closure->relay_closure == NULL)
12021202
goto close_connection;
12031203

12041204
debug_return;

logsrvd/logsrvd_relay.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,13 @@ relay_client_msg_cb(int fd, int what, void *v)
10341034
buf->len = 0;
10351035
TAILQ_REMOVE(&relay_closure->write_bufs, buf, entries);
10361036
TAILQ_INSERT_TAIL(&closure->free_bufs, buf, entries);
1037-
if (TAILQ_EMPTY(&relay_closure->write_bufs))
1037+
if (TAILQ_EMPTY(&relay_closure->write_bufs)) {
1038+
/* Write queue empty, check state. */
10381039
sudo_ev_del(closure->evbase, relay_closure->write_ev);
1040+
if (closure->error || closure->state == FINISHED ||
1041+
closure->state == SHUTDOWN)
1042+
goto close_connection;
1043+
}
10391044
}
10401045
debug_return;
10411046

0 commit comments

Comments
 (0)