@@ -9723,6 +9723,7 @@ static int DoChannelRequest(WOLFSSH* ssh,
97239723 else if (WSTRNCMP(type, "window-change", typeSz) == 0) {
97249724 word32 widthChar, heightRows, widthPixels, heightPixels;
97259725
9726+ wantReply = 0; /* RFC 4254 §6.7: no reply for window-change */
97269727 ret = GetUint32(&widthChar, buf, len, &begin);
97279728 if (ret == WS_SUCCESS)
97289729 ret = GetUint32(&heightRows, buf, len, &begin);
@@ -9752,6 +9753,7 @@ static int DoChannelRequest(WOLFSSH* ssh,
97529753 #endif /* WOLFSSH_SHELL && WOLFSSH_TERM */
97539754 #if defined(WOLFSSH_TERM) || defined(WOLFSSH_SHELL)
97549755 else if (WSTRNCMP(type, "exit-status", typeSz) == 0) {
9756+ wantReply = 0; /* RFC 4254 §6.10: no reply for exit-status */
97559757 ret = GetUint32(&ssh->exitStatus, buf, len, &begin);
97569758 WLOG(WS_LOG_AGENT, "Got exit status %u.", ssh->exitStatus);
97579759 }
@@ -9760,6 +9762,7 @@ static int DoChannelRequest(WOLFSSH* ssh,
97609762 word32 sigSz;
97619763 byte coreDumped;
97629764
9765+ wantReply = 0; /* RFC 4254 §6.10: no reply for exit-signal */
97639766 WLOG(WS_LOG_AGENT, "Got exit signal, remote command terminated");
97649767
97659768 sigSz = WOLFSSH_MAX_NAMESZ;
@@ -9822,6 +9825,9 @@ static int DoChannelRequest(WOLFSSH* ssh,
98229825
98239826static int DoChannelSuccess(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
98249827{
9828+ WOLFSSH_CHANNEL* channel = NULL;
9829+ word32 begin;
9830+ word32 channelId;
98259831 int ret = WS_SUCCESS;
98269832
98279833 WLOG(WS_LOG_DEBUG, "Entering DoChannelSuccess()");
@@ -9832,7 +9838,20 @@ static int DoChannelSuccess(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
98329838 return ret;
98339839 }
98349840
9835- ssh->serverState = SERVER_DONE;
9841+ begin = *idx;
9842+ ret = GetUint32(&channelId, buf, len, &begin);
9843+
9844+ if (ret == WS_SUCCESS) {
9845+ channel = ChannelFind(ssh, channelId, WS_CHANNEL_ID_SELF);
9846+ if (channel == NULL)
9847+ ret = WS_INVALID_CHANID;
9848+ }
9849+
9850+ if (ret == WS_SUCCESS) {
9851+ WLOG(WS_LOG_DEBUG, " channelId = %u", channelId);
9852+ *idx = begin;
9853+ ssh->serverState = SERVER_DONE;
9854+ }
98369855
98379856 WLOG(WS_LOG_DEBUG, "Leaving DoChannelSuccess(), ret = %d", ret);
98389857 return ret;
@@ -9841,15 +9860,34 @@ static int DoChannelSuccess(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
98419860
98429861static int DoChannelFailure(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
98439862{
9863+ WOLFSSH_CHANNEL* channel = NULL;
9864+ word32 begin;
9865+ word32 channelId;
98449866 int ret = WS_SUCCESS;
98459867
98469868 WLOG(WS_LOG_DEBUG, "Entering DoChannelFailure()");
98479869
9848- if (ssh == NULL || buf == NULL || len == 0 || idx == NULL)
9870+ if (ssh == NULL || buf == NULL || len == 0 || idx == NULL) {
98499871 ret = WS_BAD_ARGUMENT;
9872+ WLOG(WS_LOG_DEBUG, "Leaving DoChannelFailure(), ret = %d", ret);
9873+ return ret;
9874+ }
98509875
9851- if (ret == WS_SUCCESS)
9876+ begin = *idx;
9877+ ret = GetUint32(&channelId, buf, len, &begin);
9878+
9879+ if (ret == WS_SUCCESS) {
9880+ channel = ChannelFind(ssh, channelId, WS_CHANNEL_ID_SELF);
9881+ if (channel == NULL)
9882+ ret = WS_INVALID_CHANID;
9883+ }
9884+
9885+ if (ret == WS_SUCCESS) {
9886+ WLOG(WS_LOG_DEBUG, " channelId = %u", channelId);
9887+ *idx = begin;
98529888 ret = WS_CHANOPEN_FAILED;
9889+ }
9890+
98539891 WLOG(WS_LOG_DEBUG, "Leaving DoChannelFailure(), ret = %d", ret);
98549892 return ret;
98559893}
@@ -9924,10 +9962,17 @@ static int DoChannelData(WOLFSSH* ssh,
99249962 *idx = begin + dataSz;
99259963
99269964 channel = ChannelFind(ssh, channelId, WS_CHANNEL_ID_SELF);
9927- if (channel == NULL)
9965+ if (channel == NULL) {
99289966 ret = WS_INVALID_CHANID;
9929- else
9930- ret = ChannelPutData(channel, buf + begin, dataSz);
9967+ }
9968+ else {
9969+ if (dataSz > channel->maxPacketSz) {
9970+ ret = WS_RECV_OVERFLOW_E;
9971+ }
9972+ else {
9973+ ret = ChannelPutData(channel, buf + begin, dataSz);
9974+ }
9975+ }
99319976 }
99329977
99339978 if (ret == WS_SUCCESS) {
@@ -9987,6 +10032,8 @@ static int DoChannelExtendedData(WOLFSSH* ssh,
998710032 channel = ChannelFind(ssh, channelId, WS_CHANNEL_ID_SELF);
998810033 if (channel == NULL)
998910034 ret = WS_INVALID_CHANID;
10035+ else if (dataSz > channel->maxPacketSz)
10036+ ret = WS_RECV_OVERFLOW_E;
999010037 else {
999110038 ret = PutBuffer(&ssh->extDataBuffer, buf + begin, dataSz);
999210039 #ifdef DEBUG_WOLFSSH
@@ -16922,6 +16969,13 @@ int SendChannelData(WOLFSSH* ssh, word32 channelId,
1692216969 }
1692316970 }
1692416971
16972+ if (ret == WS_SUCCESS) {
16973+ if (channel->eofTxd) {
16974+ WLOG(WS_LOG_DEBUG, "Cannot send data after EOF");
16975+ ret = WS_EOF;
16976+ }
16977+ }
16978+
1692516979 if (ret == WS_SUCCESS) {
1692616980 if (channel->peerWindowSz == 0) {
1692716981 WLOG(WS_LOG_DEBUG, "channel window is full");
@@ -17028,6 +17082,13 @@ int SendChannelExtendedData(WOLFSSH* ssh, word32 channelId,
1702817082 }
1702917083 }
1703017084
17085+ if (ret == WS_SUCCESS) {
17086+ if (channel->eofTxd) {
17087+ WLOG(WS_LOG_DEBUG, "Cannot send data after EOF");
17088+ ret = WS_EOF;
17089+ }
17090+ }
17091+
1703117092 if (ret == WS_SUCCESS) {
1703217093 if (channel->peerWindowSz == 0) {
1703317094 WLOG(WS_LOG_DEBUG, "channel window is full");
@@ -18107,6 +18168,30 @@ int wolfSSH_TestChannelPutData(WOLFSSH_CHANNEL* channel, byte* data,
1810718168 return ChannelPutData(channel, data, dataSz);
1810818169}
1810918170
18171+ int wolfSSH_TestDoChannelSuccess(WOLFSSH* ssh, byte* buf, word32 len,
18172+ word32* idx)
18173+ {
18174+ return DoChannelSuccess(ssh, buf, len, idx);
18175+ }
18176+
18177+ int wolfSSH_TestDoChannelFailure(WOLFSSH* ssh, byte* buf, word32 len,
18178+ word32* idx)
18179+ {
18180+ return DoChannelFailure(ssh, buf, len, idx);
18181+ }
18182+
18183+ int wolfSSH_TestDoChannelData(WOLFSSH* ssh, byte* buf, word32 len,
18184+ word32* idx)
18185+ {
18186+ return DoChannelData(ssh, buf, len, idx);
18187+ }
18188+
18189+ int wolfSSH_TestDoChannelExtendedData(WOLFSSH* ssh, byte* buf, word32 len,
18190+ word32* idx)
18191+ {
18192+ return DoChannelExtendedData(ssh, buf, len, idx);
18193+ }
18194+
1811018195int wolfSSH_TestDoUserAuthRequest(WOLFSSH* ssh, byte* buf, word32 len,
1811118196 word32* idx)
1811218197{
0 commit comments