@@ -808,6 +808,9 @@ fmt_client_hello(struct client_closure *closure)
808808 bool ret = false;
809809 debug_decl (fmt_client_hello , SUDOERS_DEBUG_UTIL );
810810
811+ if (closure -> state != RECV_HELLO )
812+ goto done ;
813+
811814 sudo_debug_printf (SUDO_DEBUG_INFO , "%s: sending ClientHello" , __func__ );
812815
813816 /* Client name + version */
@@ -818,6 +821,7 @@ fmt_client_hello(struct client_closure *closure)
818821 client_msg .type_case = CLIENT_MESSAGE__TYPE_HELLO_MSG ;
819822 ret = fmt_client_message (closure , & client_msg );
820823
824+ done :
821825 debug_return_bool (ret );
822826}
823827
@@ -1001,6 +1005,9 @@ fmt_accept_message(struct client_closure *closure, const struct eventlog *evlog)
10011005 bool ret = false;
10021006 debug_decl (fmt_accept_message , SUDOERS_DEBUG_UTIL );
10031007
1008+ if (closure -> state != SEND_ACCEPT && closure -> state != SEND_IO )
1009+ goto done ;
1010+
10041011 /*
10051012 * Fill in AcceptMessage and add it to ClientMessage.
10061013 */
@@ -1050,6 +1057,9 @@ fmt_reject_message(struct client_closure *closure, const struct eventlog *evlog)
10501057 bool ret = false;
10511058 debug_decl (fmt_reject_message , SUDOERS_DEBUG_UTIL );
10521059
1060+ if (closure -> state != SEND_REJECT && closure -> state != SEND_IO )
1061+ goto done ;
1062+
10531063 /*
10541064 * Fill in RejectMessage and add it to ClientMessage.
10551065 */
@@ -1099,6 +1109,10 @@ fmt_alert_message(struct client_closure *closure, const struct eventlog *evlog)
10991109 bool ret = false;
11001110 debug_decl (fmt_alert_message , SUDOERS_DEBUG_UTIL );
11011111
1112+ /* Alerts can happen at any time. */
1113+ if (closure -> state == ERROR )
1114+ goto done ;
1115+
11021116 /*
11031117 * Fill in AlertMessage and add it to ClientMessage.
11041118 */
@@ -1193,6 +1207,9 @@ fmt_restart_message(struct client_closure *closure)
11931207 bool ret = false;
11941208 debug_decl (fmt_restart_message , SUDOERS_DEBUG_UTIL );
11951209
1210+ if (closure -> state != SEND_RESTART )
1211+ goto done ;
1212+
11961213 sudo_debug_printf (SUDO_DEBUG_INFO ,
11971214 "%s: sending RestartMessage, [%lld, %ld]" , __func__ ,
11981215 (long long )closure -> restart -> tv_sec , closure -> restart -> tv_nsec );
@@ -1227,6 +1244,9 @@ fmt_exit_message(struct client_closure *closure, int exit_status, int error)
12271244 struct timespec run_time ;
12281245 debug_decl (fmt_exit_message , SUDOERS_DEBUG_UTIL );
12291246
1247+ if (closure -> state != SEND_IO )
1248+ goto done ;
1249+
12301250 if (sudo_gettime_awake (& run_time ) == -1 ) {
12311251 sudo_warn ("%s" , U_ ("unable to get time of day" ));
12321252 goto done ;
@@ -1304,6 +1324,9 @@ fmt_io_buf(struct client_closure *closure, int type, const char *buf,
13041324 bool ret = false;
13051325 debug_decl (fmt_io_buf , SUDOERS_DEBUG_UTIL );
13061326
1327+ if (closure -> state != SEND_IO )
1328+ goto done ;
1329+
13071330 /* Fill in IoBuffer. */
13081331 ts .tv_sec = (int64_t )delay -> tv_sec ;
13091332 ts .tv_nsec = (int32_t )delay -> tv_nsec ;
@@ -1342,6 +1365,10 @@ fmt_winsize(struct client_closure *closure, unsigned int lines,
13421365 bool ret = false;
13431366 debug_decl (fmt_winsize , SUDOERS_DEBUG_UTIL );
13441367
1368+ if (closure -> state != SEND_IO )
1369+ goto done ;
1370+
1371+
13451372 /* Fill in ChangeWindowSize message. */
13461373 ts .tv_sec = (int64_t )delay -> tv_sec ;
13471374 ts .tv_nsec = (int32_t )delay -> tv_nsec ;
@@ -1379,6 +1406,9 @@ fmt_suspend(struct client_closure *closure, const char *signame,
13791406 bool ret = false;
13801407 debug_decl (fmt_suspend , SUDOERS_DEBUG_UTIL );
13811408
1409+ if (closure -> state != SEND_IO )
1410+ goto done ;
1411+
13821412 /* Fill in CommandSuspend message. */
13831413 ts .tv_sec = (int64_t )delay -> tv_sec ;
13841414 ts .tv_nsec = (int32_t )delay -> tv_nsec ;
@@ -1889,7 +1919,7 @@ server_msg_cb(int fd, int what, void *v)
18891919 }
18901920 /* Disable further log server operations. */
18911921 client_closure_free_contents (closure );
1892- closure -> disabled = true ;
1922+ closure -> state = ERROR ;
18931923 debug_return ;
18941924}
18951925
@@ -2009,7 +2039,7 @@ client_msg_cb(int fd, int what, void *v)
20092039 }
20102040 /* Disable further log server operations. */
20112041 client_closure_free_contents (closure );
2012- closure -> disabled = true ;
2042+ closure -> state = ERROR ;
20132043 debug_return ;
20142044}
20152045
@@ -2108,9 +2138,6 @@ log_server_close(struct client_closure *closure, int exit_status, int error)
21082138 bool ret = false;
21092139 debug_decl (log_server_close , SUDOERS_DEBUG_UTIL );
21102140
2111- if (closure -> disabled )
2112- goto done ;
2113-
21142141 /* Format and append an ExitMessage to the write queue. */
21152142 if (!fmt_exit_message (closure , exit_status , error ))
21162143 goto done ;
0 commit comments