diff options
author | Pablo Yaggi <pyaggi@gmail.com> | 2021-02-09 11:39:13 +0000 |
---|---|---|
committer | Jakub Jelen <jjelen@redhat.com> | 2021-08-17 15:46:54 +0200 |
commit | 265b826f78a5db8b6336c3a19195182ad3df6556 (patch) | |
tree | 4e396e6530cb1900c5b2e3f64aeef5ccfba9c88a | |
parent | c2c56040777f859b8269fed60a3b8637ad0a8859 (diff) | |
download | libssh-265b826f78a5db8b6336c3a19195182ad3df6556.tar.gz libssh-265b826f78a5db8b6336c3a19195182ad3df6556.tar.xz libssh-265b826f78a5db8b6336c3a19195182ad3df6556.zip |
fix sftp_new_channel constructs an invalid object
Fixes T273
Signed-off-by: Pablo Yaggi <pyaggi@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
(cherry picked from commit 51b7a2421a93d55ca891d38c6a4f1350fb8fffcf)
-rw-r--r-- | src/sftp.c | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -191,14 +191,38 @@ sftp_new_channel(ssh_session session, ssh_channel channel) sftp->ext = sftp_ext_new(); if (sftp->ext == NULL) { ssh_set_error_oom(session); - SAFE_FREE(sftp); - return NULL; + goto error; + } + + sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct)); + if (sftp->read_packet == NULL) { + ssh_set_error_oom(session); + goto error; + } + + sftp->read_packet->payload = ssh_buffer_new(); + if (sftp->read_packet->payload == NULL) { + ssh_set_error_oom(session); + goto error; } sftp->session = session; sftp->channel = channel; return sftp; + +error: + if (sftp->ext != NULL) { + sftp_ext_free(sftp->ext); + } + if (sftp->read_packet != NULL) { + if (sftp->read_packet->payload != NULL) { + SSH_BUFFER_FREE(sftp->read_packet->payload); + } + SAFE_FREE(sftp->read_packet); + } + SAFE_FREE(sftp); + return NULL; } #ifdef WITH_SERVER |