Skip to content

Commit cfa504d

Browse files
committed
wolfsshd: harden windowFull retry
- Guard the retry against a negative cnt_w so a non-sentinel send error cannot become a negative memmove offset. - Clear windowFullExt at the stdout and childFd save sites so stream ownership is set unconditionally.
1 parent 795b85e commit cfa504d

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

apps/wolfsshd/wolfsshd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,10 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
16481648
wantWrite = 1;
16491649
continue;
16501650
}
1651+
else if (cnt_w < 0) {
1652+
kill(childPid, SIGINT);
1653+
break;
1654+
}
16511655
else {
16521656
windowFull -= cnt_w;
16531657
if (windowFull > 0) {
@@ -1722,16 +1726,19 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
17221726
shellBuffer, cnt_r);
17231727
if (cnt_w > 0 && cnt_w < cnt_r) { /* partial send */
17241728
windowFull = cnt_r - cnt_w;
1729+
windowFullExt = 0;
17251730
WMEMMOVE(shellBuffer, shellBuffer + cnt_w,
17261731
windowFull);
17271732
}
17281733
else if (cnt_w == WS_WINDOW_FULL ||
17291734
cnt_w == WS_REKEYING) {
17301735
windowFull = cnt_r; /* save amount to be sent */
1736+
windowFullExt = 0;
17311737
continue;
17321738
}
17331739
else if (cnt_w == WS_WANT_WRITE) {
17341740
windowFull = cnt_r;
1741+
windowFullExt = 0;
17351742
wantWrite = 1;
17361743
continue;
17371744
}
@@ -1759,16 +1766,19 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
17591766
shellBuffer, cnt_r);
17601767
if (cnt_w > 0 && cnt_w < cnt_r) { /* partial send */
17611768
windowFull = cnt_r - cnt_w;
1769+
windowFullExt = 0;
17621770
WMEMMOVE(shellBuffer, shellBuffer + cnt_w,
17631771
windowFull);
17641772
}
17651773
else if (cnt_w == WS_WINDOW_FULL ||
17661774
cnt_w == WS_REKEYING) {
17671775
windowFull = cnt_r;
1776+
windowFullExt = 0;
17681777
continue;
17691778
}
17701779
else if (cnt_w == WS_WANT_WRITE) {
17711780
windowFull = cnt_r;
1781+
windowFullExt = 0;
17721782
wantWrite = 1;
17731783
continue;
17741784
}

0 commit comments

Comments
 (0)