From c6948fd983fa1855b2dadba50aa50f576f54bdda Mon Sep 17 00:00:00 2001 From: Trumeet Date: Tue, 26 Jul 2022 21:27:24 -0700 Subject: fix(acronc): input will cause illegal memory access Cause: 1. stdin got cmd -> request 2. stdin got EOF -> ac_disconnect -> ac_conn becomes NULL 3. socket got response -> ac_receive(ac_conn) -> crash Conclusion: ordering issue between ac_disconnect and socket read. Solution: Best way: pause the input until command returns Cons: 1. Lost the advantage of background execution of commands (has to wait until done) 2. It is unreliable to determine if a command is done: although the current server implementation will not send anything else after an error or cmd_result, Minecraft server itself or future server implementations may. The spec does not say anything on termination. Acronc currently assumes that after receiving an error or cmd_result with the same request ID, it is done. Then, it resumes the stdin, reads the EOF, and then disconnect. Worse way: Directly call uv_read_stop before ac_disconnect Cons: It is going to lose anything, including command results. This is particularly undesirable for ad-hoc calls (i.e. echo list | acronc). Therefore, the current approach is to block and read as much as we can (until error or cmd_result), then stop reading the socket before disconnecting as a double safe. Signed-off-by: Trumeet --- client/acronc/handler.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'client/acronc/handler.h') diff --git a/client/acronc/handler.h b/client/acronc/handler.h index 5764387..1beab1c 100644 --- a/client/acronc/handler.h +++ b/client/acronc/handler.h @@ -15,6 +15,10 @@ int h_signal(void (*on_quit)(void)); int h_stdin(int (*on_input)(ac_request_t *req), void (*on_close)(void)); +int stdin_start(void); + +void stdin_stop(void); + int h_socket(ac_connection_parameters_t *p, const struct addrinfo *ai, void (*on_connect_result)(bool), -- cgit v1.2.3