summaryrefslogtreecommitdiff
path: root/pcr/guile-ssh/guile-ssh-0.11.3-fix-segfault.patch
blob: 787dc04c9a7ace76d30844c2658cc37c60baaa01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From c468d9c2dc343446757360857a295736359b3024 Mon Sep 17 00:00:00 2001
From: "Artyom V. Poptsov" <poptsov.artyom@gmail.com>
Date: Tue, 7 Aug 2018 07:55:00 +0300
Subject: [PATCH] libguile-ssh/channel-type.c (ptob_close): Bugfix: fix a
 segfault

'ptob_close' would always get a segfault when it tried to free a closed
channel.  This patch fixes that by adding a check if a channel is already
closed.

Reported by Michael Bowcutt <mbowcutt@case.edu> in
  <https://github.com/artyom-poptsov/guile-ssh/issues/8>
  and Njagi Mwaniki in a personal email.

* libguile-ssh/channel-type.c (ptob_close): Check if a channel is already
  closed before trying to close and free it.  Improve logging.
* libguile-ssh/log.c (_gssh_log_debug, _gssh_log_debug1): New procedures
* libguile-ssh/log.h: Likewise.
---
 libguile-ssh/channel-type.c | 10 +++++++++-
 libguile-ssh/log.c          | 21 +++++++++++++++++++++
 libguile-ssh/log.h          |  3 +++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/libguile-ssh/channel-type.c b/libguile-ssh/channel-type.c
index ffcca64..4b0b9ae 100644
--- a/libguile-ssh/channel-type.c
+++ b/libguile-ssh/channel-type.c
@@ -29,6 +29,7 @@
 #include "channel-type.h"
 #include "error.h"
 #include "common.h"
+#include "log.h"
 
 
 /* The channel port type.  Guile 2.2 introduced a new port API, so we have a
@@ -223,10 +224,17 @@ ptob_close (SCM channel)
   ptob_flush (channel);
 #endif
 
-  if (ch)
+  if (ch && ssh_channel_is_open (ch->ssh_channel))
     {
+      _gssh_log_debug ("ptob_close", "closing and freeing the channel...",
+                       channel);
       ssh_channel_close (ch->ssh_channel);
       ssh_channel_free (ch->ssh_channel);
+      _gssh_log_debug1 ("ptob_close", "closing and freeing the channel... done");
+    }
+  else
+    {
+      _gssh_log_debug1 ("ptob_close", "the channel is already freeed.");
     }
 
   SCM_SETSTREAM (channel, NULL);
diff --git a/libguile-ssh/log.c b/libguile-ssh/log.c
index 6588749..e0e3027 100644
--- a/libguile-ssh/log.c
+++ b/libguile-ssh/log.c
@@ -270,6 +270,27 @@ _gssh_log_warning (const char* function_name, const char* msg, SCM args)
   scm_dynwind_end ();
 }
 
+void
+_gssh_log_debug (const char* function_name, const char* msg, SCM args)
+{
+  char *c_str;
+  scm_dynwind_begin (0);
+
+  c_str = scm_to_locale_string (scm_object_to_string (args, SCM_UNDEFINED));
+  scm_dynwind_free (c_str);
+
+  _ssh_log (SSH_LOG_FUNCTIONS, function_name, "[GSSH DEBUG] %s: %s",
+            msg, c_str);
+
+  scm_dynwind_end ();
+}
+
+void
+_gssh_log_debug1 (const char* function_name, const char* msg)
+{
+  _ssh_log (SSH_LOG_FUNCTIONS, function_name, "[GSSH DEBUG] %s", msg);
+}
+
 
 /* Initialization */
 
diff --git a/libguile-ssh/log.h b/libguile-ssh/log.h
index dd1424b..c3fe866 100644
--- a/libguile-ssh/log.h
+++ b/libguile-ssh/log.h
@@ -28,6 +28,9 @@ extern void _gssh_log_error (const char* function_name, const char* msg,
 
 extern void _gssh_log_warning (const char* function_name, const char* msg,
                                SCM args);
+extern void _gssh_log_debug (const char* function_name, const char* msg,
+                             SCM args);
+extern void _gssh_log_debug1 (const char* function_name, const char* msg);
 
 extern void init_log_func (void);
 
-- 
2.20.1