From 2fbe01092d88e37bbd598c3eba26ff3149a08e06 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Mon, 5 Aug 2024 14:48:51 -0600 Subject: [PATCH] account for partial sends --- apps/wolfsshd/wolfsshd.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/wolfsshd/wolfsshd.c b/apps/wolfsshd/wolfsshd.c index 36206a663..31adce293 100644 --- a/apps/wolfsshd/wolfsshd.c +++ b/apps/wolfsshd/wolfsshd.c @@ -1515,8 +1515,10 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, } else { windowFull -= cnt_w; - if (windowFull > 0) + if (windowFull > 0) { + WMEMMOVE(shellBuffer, shellBuffer + cnt_w, windowFull); continue; + } if (windowFull < 0) windowFull = 0; } @@ -1537,7 +1539,13 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, if (cnt_r > 0) { cnt_w = wolfSSH_extended_data_send(ssh, shellBuffer, cnt_r); - if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) { + if (cnt_w > 0 && cnt_w < cnt_r) { /* partial send */ + windowFull = cnt_r - cnt_w; + WMEMMOVE(shellBuffer, shellBuffer + cnt_w, + windowFull); + } + else if (cnt_w == WS_WINDOW_FULL || + cnt_w == WS_REKEYING) { windowFull = cnt_r; /* save amount to be sent */ continue; } @@ -1569,7 +1577,13 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, if (cnt_r > 0) { cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId, shellBuffer, cnt_r); - if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) { + if (cnt_w > 0 && cnt_w < cnt_r) { /* partial send */ + windowFull = cnt_r - cnt_w; + WMEMMOVE(shellBuffer, shellBuffer + cnt_w, + windowFull); + } + else if (cnt_w == WS_WINDOW_FULL || + cnt_w == WS_REKEYING) { windowFull = cnt_r; /* save amount to be sent */ continue; } @@ -1599,7 +1613,13 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, if (cnt_r > 0) { cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId, shellBuffer, cnt_r); - if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) { + if (cnt_w > 0 && cnt_w < cnt_r) { /* partial send */ + windowFull = cnt_r - cnt_w; + WMEMMOVE(shellBuffer, shellBuffer + cnt_w, + windowFull); + } + else if (cnt_w == WS_WINDOW_FULL || + cnt_w == WS_REKEYING) { windowFull = cnt_r; continue; }