[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] sftpserver: allocate packet on sftp_server_new


Ensure sftp_server_new allocates the packet and payload as
sftp_packet_read now expects the packet and payload to be
pre-allocated.

Similarly, ensure sftp_get_client_message does not free the packet.

Signed-off-by: Alberto Aguirre <albaguirre@xxxxxxxxx>
---
 src/sftp.c       | 21 +++++++++++++++++++++
 src/sftpserver.c |  2 --
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/sftp.c b/src/sftp.c
index 9a98d444..9dec687a 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -211,10 +211,31 @@ sftp_session sftp_server_new(ssh_session session, ssh_channel chan){
     return NULL;
   }
 
+  sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct));
+  if (sftp->read_packet == NULL) {
+    goto error;
+  }
+
+  sftp->read_packet->payload = ssh_buffer_new();
+  if (sftp->read_packet->payload == NULL) {
+    goto error;
+  }
+
   sftp->session = session;
   sftp->channel = chan;
 
   return sftp;
+
+error:
+  ssh_set_error_oom(session);
+  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;
 }
 
 int sftp_server_init(sftp_session sftp){
diff --git a/src/sftpserver.c b/src/sftpserver.c
index 3cb30090..1717aa41 100644
--- a/src/sftpserver.c
+++ b/src/sftpserver.c
@@ -232,8 +232,6 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
       return NULL;
   }
 
-  sftp_packet_free(packet);
-
   return msg;
 }
 
-- 
2.17.1


Archive administrator: postmaster@lists.cynapses.org