Prevent forwarding threads from sending on closed tunnels

- Add tunnel validity check in forwarding threads before sending data
- Threads check if tunnel is still active in the global list before proceeding
- Prevents SSL write errors and connection corruption when tunnels are closed
parent 9aeacb3d
...@@ -345,6 +345,13 @@ void *forward_tcp_to_ws(void *arg) { ...@@ -345,6 +345,13 @@ void *forward_tcp_to_ws(void *arg) {
continue; continue;
} }
// Check if tunnel is still active after copying values
tunnel_t *check_tunnel = find_tunnel_by_request_id(request_id);
if (!check_tunnel || !check_tunnel->active) {
pthread_mutex_unlock(&tunnel_mutex);
break;
}
// For wsscp: The connection should already be established // For wsscp: The connection should already be established
int client_sock = sock; int client_sock = sock;
if (tunnel->sock < 0 && tunnel->outgoing_buffer) { if (tunnel->sock < 0 && tunnel->outgoing_buffer) {
...@@ -522,6 +529,15 @@ void *forward_ws_to_ssh_server(void *arg) { ...@@ -522,6 +529,15 @@ void *forward_ws_to_ssh_server(void *arg) {
strcpy(request_id, tunnel->request_id); strcpy(request_id, tunnel->request_id);
pthread_mutex_unlock(&tunnel_mutex); pthread_mutex_unlock(&tunnel_mutex);
// Check if tunnel is still active after copying values
pthread_mutex_lock(&tunnel_mutex);
tunnel_t *check_tunnel = find_tunnel_by_request_id(request_id);
if (!check_tunnel || !check_tunnel->active) {
pthread_mutex_unlock(&tunnel_mutex);
break;
}
pthread_mutex_unlock(&tunnel_mutex);
// Use select to wait for data on target TCP connection // Use select to wait for data on target TCP connection
FD_ZERO(&readfds); FD_ZERO(&readfds);
FD_SET(target_sock, &readfds); FD_SET(target_sock, &readfds);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment