mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 20:30:38 +09:00
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>
(cherry picked from commit be8302e2f3)
This commit is contained in:
20
src/sftp.c
20
src/sftp.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user