diff --git a/libssh/agent.c b/libssh/agent.c index 3a8c56ee..8a938907 100644 --- a/libssh/agent.c +++ b/libssh/agent.c @@ -124,6 +124,9 @@ AGENT *agent_new(struct ssh_session *session) { if (agent) { agent->count = 0; agent->sock = ssh_socket_new(session); + if (agent->sock == NULL) { + return NULL; + } } return agent; diff --git a/libssh/session.c b/libssh/session.c index 0feaabc5..1ba30d8d 100644 --- a/libssh/session.c +++ b/libssh/session.c @@ -52,9 +52,16 @@ SSH_SESSION *ssh_new(void) { session->out_buffer=buffer_new(); session->in_buffer=buffer_new(); #ifndef _WIN32 - session->agent=agent_new(session); + session->agent = agent_new(session); + if (session->agent == NULL) { + goto err; + } #endif /* _WIN32 */ return session; + +err: + ssh_cleanup(session); + return NULL; } void ssh_cleanup(SSH_SESSION *session){ diff --git a/libssh/socket.c b/libssh/socket.c index acadbeda..03797d61 100644 --- a/libssh/socket.c +++ b/libssh/socket.c @@ -89,7 +89,12 @@ void ssh_socket_init(void) { * \brief creates a new Socket object */ struct socket *ssh_socket_new(SSH_SESSION *session){ - struct socket *s=malloc(sizeof(struct socket)); + struct socket *s; + + s = malloc(sizeof(struct socket)); + if (s = NULL) { + return NULL; + } s->fd=-1; s->last_errno=-1; s->session=session; @@ -351,6 +356,10 @@ int ssh_socket_wait_for_data(struct socket *s, SSH_SESSION *session, u32 len){ } if(session->blocking){ buf=malloc(to_read); + if (buf == NULL) { + leave_function(); + return SSH_ERROR; + } r=ssh_socket_completeread(session->socket,buf,to_read); if(r==SSH_ERROR || r ==0){ ssh_set_error(session,SSH_FATAL,