diff options
| author | Artyom V. Poptsov <poptsov.artyom@gmail.com> | 2017-05-21 20:45:20 +0300 |
|---|---|---|
| committer | Artyom V. Poptsov <poptsov.artyom@gmail.com> | 2017-05-21 20:45:20 +0300 |
| commit | cb6dc775411ac12617a620fa77e763fe0fc0828e (patch) | |
| tree | f2e0f32472beab8114ae3933371dbfbe6c3431b1 /libguile-ssh | |
| parent | log.c (_gssh_log_warning): New procedure (diff) | |
| download | guile-ssh-cb6dc775411ac12617a620fa77e763fe0fc0828e.tar.gz | |
channel-type.c (print_channel): Bugfix: Handle freed channels
Guile-SSH would always crash with SIGSEGV errors when tried to print a freed
channel object (e.g. after calling 'close' on a channel). This patch fixes
the bug.
* libguile-ssh/channel-type.c (print_channel): Bugfix: Handle freed channels
properly.
* tests/client-server.scm ("channel-request-exec, printing a freed channel"):
New test case.
* NEWS: Update.
Diffstat (limited to 'libguile-ssh')
| -rw-r--r-- | libguile-ssh/channel-type.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/libguile-ssh/channel-type.c b/libguile-ssh/channel-type.c index 3dd641f..cc9dae6 100644 --- a/libguile-ssh/channel-type.c +++ b/libguile-ssh/channel-type.c @@ -1,6 +1,6 @@ /* channel-type.c -- SSH channel smob. * - * Copyright (C) 2013, 2014, 2015 Artyom V. Poptsov <poptsov.artyom@gmail.com> + * Copyright (C) 2013, 2014, 2015, 2016, 2017 Artyom V. Poptsov <poptsov.artyom@gmail.com> * Copyright (C) 2017 Ludovic Courtès <ludo@gnu.org> * * This file is part of Guile-SSH. @@ -244,24 +244,30 @@ ptob_close (SCM channel) static int print_channel (SCM channel, SCM port, scm_print_state *pstate) { - struct channel_data *ch = _scm_to_channel_data (channel); + struct channel_data *ch = NULL; + + if (SCM_PTAB_ENTRY (channel)) + ch = _scm_to_channel_data (channel); scm_puts ("#<", port); - scm_print_port_mode (channel, port); - scm_puts ("channel ", port); if (! ch) { - scm_puts ("(freed) ", port); - } - else if (SCM_OPPORTP (channel)) - { - int is_open = ssh_channel_is_open (ch->ssh_channel); - scm_puts (is_open ? "(open) " : "(closed) ", port); + scm_puts ("unknown channel (freed) ", port); } else { - scm_puts ("(closed) ", port); + scm_print_port_mode (channel, port); + scm_puts ("channel ", port); + if (SCM_OPPORTP (channel)) + { + int is_open = ssh_channel_is_open (ch->ssh_channel); + scm_puts (is_open ? "(open) " : "(closed) ", port); + } + else + { + scm_puts ("(closed) ", port); + } } scm_display (_scm_object_hex_address (channel), port); scm_puts (">", port); |
