guacamole-server/src
sanhex d33bd8deff GUACAMOLE-384: fixing segfault during ssh disconnect
Root Cause:
See the core dump and Valgrind report posted on Jira. guacd was reading a ssh terminal which had been freed. When a ssh connection is terminated, guac_ssh_client_free_handler() will be called from guacd_exec_proc() -> guac_client_free() with pointer client->free_handler. In guac_ssh_client_free_handler(), when ssh_client->term is freed, ssh_client->client_thread may still be using the ssh_client->term. It causes the crash reported in this bug.

The stack trace exposing the problem can be found by running guacd under Valgrind with a ssh test script. The test script repeats doing ssh login and logout for 5000 times.

Solution:
In guac_ssh_client_free_handler(), before calling guac_terminal_free(ssh_client->term), close the stdin pipe of the terminal to stop reading the pipe with guac_terminal_read_stdin() in ssh_input_thread(). So that ssh_input_thread() can be terminated in this case. Call pthread_join() to wait for ssh_client_thread() terminating before freeing the terminal.

Add a new function guac_terminal_stop() to close the pipe and set the fds to invalid (-1). Call it in guac_ssh_client_free_handler() and guac_terminal_free().

Checking the client running state in ssh_input_thread() and ssh_client_thread() to make sure they can be terminated when the client is stopped in guacd_exec_proc() by another thread.

Test:
- Confirmed ssh connection works normally.
- Observed the child process of guacd exits when ssh connection is terminated.
- Reran the ssh test script. Observed no crash.
2017-10-29 18:11:15 -07:00
..
common GUACAMOLE-325: Do not lock files on Windows. Use Windows-specific _mkdir() call where necessary. 2017-07-05 20:55:02 -07:00
common-ssh GUACAMOLE-396: Fixing ssh socket for IPv6 address 2017-09-26 17:19:18 -07:00
guacd GUACAMOLE-391: resolve low impact memory leak 2017-09-24 13:42:59 +05:00
guacd-docker GUACAMOLE-97: Update guacd Docker README.md with respect to Apache. 2016-10-04 12:25:07 -07:00
guacenc GUACAMOLE-314: Bump version numbers to 0.9.13-incubating. 2017-06-01 22:48:02 -07:00
libguac GUACAMOLE-325: Add Winsock-specific guac_socket implementation. 2017-07-05 20:55:03 -07:00
protocols GUACAMOLE-384: fixing segfault during ssh disconnect 2017-10-29 18:11:15 -07:00
pulse GUACAMOLE-240: Document parameters and behavior of PulseAudio callbacks. 2017-03-15 22:26:11 -07:00
terminal GUACAMOLE-384: fixing segfault during ssh disconnect 2017-10-29 18:11:15 -07:00