diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-09-08 09:29:57 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-09-17 10:48:49 +0200 |
commit | be8302e2f3277bd25c305fb6fc14063e0e4ec945 (patch) | |
tree | 796802d8ac766f2e1366ea975b0e2ba6f33fd7c0 /src/sftp.c | |
parent | 97d2e1f4cb7bf7e2434685a20c9a78cf28b3b44b (diff) | |
download | libssh-be8302e2f3277bd25c305fb6fc14063e0e4ec945.tar.gz libssh-be8302e2f3277bd25c305fb6fc14063e0e4ec945.tar.xz libssh-be8302e2f3277bd25c305fb6fc14063e0e4ec945.zip |
sftp: Allocate a new buffer in sftp_packet_read() if needed
We will move the buffer to the message instead of duplicating the
memory.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/sftp.c')
-rw-r--r-- | src/sftp.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -339,10 +339,22 @@ sftp_packet sftp_packet_read(sftp_session sftp) packet->sftp = sftp; - rc = ssh_buffer_reinit(packet->payload); - if (rc != 0) { - ssh_set_error_oom(sftp->session); - return NULL; + /* + * If the packet has a payload, then just reinit the buffer, otherwise + * allocate a new one. + */ + if (packet->payload != NULL) { + rc = ssh_buffer_reinit(packet->payload); + if (rc != 0) { + ssh_set_error_oom(sftp->session); + return NULL; + } + } else { + packet->payload = ssh_buffer_new(); + if (packet->payload == NULL) { + ssh_set_error_oom(sftp->session); + return NULL; + } } nread = 0; |