From b9c8387c5ae3178d3eb65ad7b9d9683717d5012b Mon Sep 17 00:00:00 2001
From: Jakub Jelen <jjelen@redhat.com>
Date: Tue, 5 Sep 2023 17:33:41 +0200
Subject: [PATCH] libssh: Implement SFTP packet size limit

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
---
 lib/vssh/libssh.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c
index dea0084575859b..ba2573ec052271 100644
--- a/lib/vssh/libssh.c
+++ b/lib/vssh/libssh.c
@@ -2567,6 +2567,11 @@ static ssize_t sftp_send(struct Curl_easy *data, int sockindex,
   struct connectdata *conn = data->conn;
   (void)sockindex;
 
+  /* limit the writes to the maximum specified in Section 3 of
+   * https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-02
+   */
+  len = len > 32768 ? 32768 : len;
+
   nwrite = sftp_write(conn->proto.sshc.sftp_file, mem, len);
 
   myssh_block2waitfor(conn, FALSE);
