More memory error checks for ssh_socket_new().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@329 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-01 20:24:09 +00:00
parent b06c167775
commit 1b627b3867
3 changed files with 37 additions and 16 deletions

View File

@@ -186,6 +186,14 @@ SSH_SESSION *ssh_bind_accept(SSH_BIND *ssh_bind){
ssh_socket_free(session->socket);
session->socket=ssh_socket_new(session);
if (session->socket == NULL) {
if (dsa)
private_key_free(dsa);
if (rsa)
private_key_free(rsa);
ssh_cleanup(session);
return NULL;
}
ssh_socket_set_fd(session->socket,fd);
session->dsa_key=dsa;
session->rsa_key=rsa;

View File

@@ -45,6 +45,9 @@ SSH_SESSION *ssh_new(void) {
session->next_crypto=crypto_new();
session->maxchannel=FIRST_CHANNEL;
session->socket = ssh_socket_new(session);
if (session->socket == NULL) {
goto err;
}
session->alive=0;
session->auth_methods=0;
session->blocking=1;

View File

@@ -92,17 +92,27 @@ struct socket *ssh_socket_new(SSH_SESSION *session){
struct socket *s;
s = malloc(sizeof(struct socket));
if (s = NULL) {
if (s == NULL) {
return NULL;
}
s->fd = -1;
s->last_errno = -1;
s->session = session;
s->in_buffer = buffer_new();
if (s->in_buffer == NULL) {
SAFE_FREE(s);
return NULL;
}
s->out_buffer=buffer_new();
if (s->out_buffer == NULL) {
buffer_free(s->in_buffer);
SAFE_FREE(s);
return NULL;
}
s->data_to_read = 0;
s->data_to_write = 0;
s->data_except = 0;
return s;
}