#265: agent_disconnect_unix closes stdin on Solaris 10 x64
-------------------------+--------------------
 Reporter:  mkerestesch  |       Owner:
     Type:  defect       |      Status:  new
 Priority:  normal       |   Milestone:  1.4.3
Component:  SFTP         |     Version:  1.4.2
 Keywords:               |  Blocked By:
   Blocks:               |
-------------------------+--------------------
 Hi there.
 i'm, using libssh2 1.4.3 in a multi-threaded environment to connect to an
 sftp-server via curl (curl 7.30.0, openssl 1.0.1e).
 My code is working perfectly in a windows 7, Linux x64, Solaris 11 x64 and
 Mac OS X x64 environment, but shutting down a thread local curl
 handle under Solaris 10 x64 somehow seems to close stdin (which i rely on
 due to ipc-requirements).
 Anyway. I was able to generate a stacktrace for the problem and the
 offending call seems to be agent_disconnect_unix, which obviously
 closes fd with fd == 0.
 As I can see from libssh2_agent_init the LIBSSH_AGENT struct is zeroed,
 which also sets fd to zero.
 Changing (agent.c):

 LIBSSH2_API LIBSSH2_AGENT *
 libssh2_agent_init(LIBSSH2_SESSION *session)
 {
     LIBSSH2_AGENT *agent;

     agent = LIBSSH2_ALLOC(session, sizeof *agent);
     if (!agent) {
         _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
                        "Unable to allocate space for agent connection");
         return NULL;
     }
     memset(agent, 0, sizeof *agent);
     agent->session = session;
     _libssh2_list_init(&agent->head);

     return agent;
 }

 to

 LIBSSH2_API LIBSSH2_AGENT *
 libssh2_agent_init(LIBSSH2_SESSION *session)
 {
     LIBSSH2_AGENT *agent;

     agent = LIBSSH2_ALLOC(session, sizeof *agent);
     if (!agent) {
         _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
                        "Unable to allocate space for agent connection");
         return NULL;
     }
     memset(agent, 0, sizeof *agent);
     agent->fd = LIBSSH2_INVALID_SOCKET;
     agent->session = session;
     _libssh2_list_init(&agent->head);

     return agent;
 }

 fixed the problem for me. Still strange that this incident does not pop up
 on other platforms….

 Attached you'll find a dbx stack trace.

 Regards, Matt

-- 
Ticket URL: <https://trac.libssh2.org/ticket/265>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Reply via email to