Fix socket availability issue in handle_tunnel_data

- Added check for valid target socket before attempting to send data
- Prevents 'Bad file descriptor' errors when local socket isn't ready yet
- Added debug message when target socket is not available
- Ensures tunnel_data messages are ignored until SSH connection is established
- Fixes race condition between WebSocket message arrival and SSH client connection
parent 8ed44cda
...@@ -412,7 +412,7 @@ void handle_tunnel_data(SSL *ssl __attribute__((unused)), const char *request_id ...@@ -412,7 +412,7 @@ void handle_tunnel_data(SSL *ssl __attribute__((unused)), const char *request_id
return; return;
} }
int target_sock; int target_sock = -1;
if (active_tunnel->outgoing_buffer) { if (active_tunnel->outgoing_buffer) {
// wsscp: Use local_sock // wsscp: Use local_sock
target_sock = active_tunnel->local_sock; target_sock = active_tunnel->local_sock;
...@@ -423,6 +423,16 @@ void handle_tunnel_data(SSL *ssl __attribute__((unused)), const char *request_id ...@@ -423,6 +423,16 @@ void handle_tunnel_data(SSL *ssl __attribute__((unused)), const char *request_id
// wsssh: Use local_sock // wsssh: Use local_sock
target_sock = active_tunnel->local_sock; target_sock = active_tunnel->local_sock;
} }
// Check if target socket is valid
if (target_sock < 0) {
if (debug) {
printf("[DEBUG] Target socket not ready yet, ignoring tunnel_data\n");
fflush(stdout);
}
pthread_mutex_unlock(&tunnel_mutex);
return;
}
pthread_mutex_unlock(&tunnel_mutex); pthread_mutex_unlock(&tunnel_mutex);
// Validate hex data length // Validate hex data length
......
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