Fix bad descriptor in wsssh by sending buffered server response immediately...

Fix bad descriptor in wsssh by sending buffered server response immediately after accepting SSH client connection

- Send server's SSH version response immediately to the forked SSH process to prevent timeout
- This ensures the SSH version exchange completes before the client closes the connection
parent 9356f699
...@@ -472,6 +472,23 @@ int main(int argc, char *argv[]) { ...@@ -472,6 +472,23 @@ int main(int argc, char *argv[]) {
// Set the accepted socket with mutex protection // Set the accepted socket with mutex protection
pthread_mutex_lock(&tunnel_mutex); pthread_mutex_lock(&tunnel_mutex);
active_tunnel->local_sock = accepted_sock; active_tunnel->local_sock = accepted_sock;
// Send any buffered data to the SSH client immediately
if (active_tunnel->incoming_buffer && active_tunnel->incoming_buffer->used > 0) {
if (config.debug) {
printf("[DEBUG - Tunnel] Sending %zu bytes of buffered server response to SSH client\n", active_tunnel->incoming_buffer->used);
fflush(stdout);
}
ssize_t sent = send(accepted_sock, active_tunnel->incoming_buffer->buffer, active_tunnel->incoming_buffer->used, 0);
if (sent > 0) {
frame_buffer_consume(active_tunnel->incoming_buffer, sent);
if (config.debug) {
printf("[DEBUG] Sent %zd bytes of buffered server response to SSH client\n", sent);
fflush(stdout);
}
}
}
pthread_mutex_unlock(&tunnel_mutex); pthread_mutex_unlock(&tunnel_mutex);
if (config.debug) { if (config.debug) {
......
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