mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +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>
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;
|
packet->sftp = sftp;
|
||||||
|
|
||||||
rc = ssh_buffer_reinit(packet->payload);
|
/*
|
||||||
if (rc != 0) {
|
* If the packet has a payload, then just reinit the buffer, otherwise
|
||||||
ssh_set_error_oom(sftp->session);
|
* allocate a new one.
|
||||||
return NULL;
|
*/
|
||||||
|
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;
|
nread = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user