aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-09-08 09:29:57 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-09-17 10:48:49 +0200
commitbe8302e2f3277bd25c305fb6fc14063e0e4ec945 (patch)
tree796802d8ac766f2e1366ea975b0e2ba6f33fd7c0
parent97d2e1f4cb7bf7e2434685a20c9a78cf28b3b44b (diff)
downloadlibssh-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>
-rw-r--r--src/sftp.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/sftp.c b/src/sftp.c
index fdcffcd7..a1f1062e 100644
--- a/src/sftp.c
+++ b/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;