From cb6dc775411ac12617a620fa77e763fe0fc0828e Mon Sep 17 00:00:00 2001 From: "Artyom V. Poptsov" Date: Sun, 21 May 2017 20:45:20 +0300 Subject: 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. --- libguile-ssh/channel-type.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'libguile-ssh') 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 + * Copyright (C) 2013, 2014, 2015, 2016, 2017 Artyom V. Poptsov * Copyright (C) 2017 Ludovic Courtès * * 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); -- cgit v1.2.3