agent_disconnect_unix", called by "libssh2_agent_disconnect", was leaving the file descriptor in the agent structure unchanged. Later, "libssh2_agent_free" would call again "libssh2_agent_disconnect" under the hood and it would try to close again the same file descriptor. In most cases that resulted in just a harmless error, but it is also possible that the file descriptor had been reused between the two calls resulting in the closing of an unrelated file descriptor.
This patch sets agent->fd to LIBSSH2_INVALID_SOCKET avoiding that issue.
>From de2afe816035354ef58fec03094c869fca4b95b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20Fandi=C3=B1o?= <[email protected]> Date: Sat, 5 Dec 2015 21:16:13 +0100 Subject: [PATCH] agent_disconnect_unix: unset the agent fd after closing it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "agent_disconnect_unix", called by "libssh2_agent_disconnect", was leaving the file descriptor in the agent structure unchanged. Later, "libssh2_agent_free" would call again "libssh2_agent_disconnect" under the hood and it would try to close again the same file descriptor. In most cases that resulted in just a harmless error, but it is also possible that the file descriptor had been reused between the two calls resulting in the closing of an unrelated file descriptor. This patch sets agent->fd to LIBSSH2_INVALID_SOCKET avoiding that issue. Signed-off-by: Salvador Fandiño <[email protected]> --- src/agent.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/agent.c b/src/agent.c index b797cbd..e771643 100644 --- a/src/agent.c +++ b/src/agent.c @@ -239,8 +239,9 @@ agent_disconnect_unix(LIBSSH2_AGENT *agent) { int ret; ret = close(agent->fd); - - if(ret == -1) + if(ret != -1) + agent->fd = LIBSSH2_INVALID_SOCKET; + else return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT, "failed closing the agent socket"); return LIBSSH2_ERROR_NONE; -- 2.5.0
_______________________________________________ libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
