@@ -718,6 +718,75 @@ static int test_DoUserAuthBanner(void)
718718 return result ;
719719}
720720
721+ static int test_ChannelPutData (void )
722+ {
723+ WOLFSSH_CTX * ctx = NULL ;
724+ WOLFSSH * ssh = NULL ;
725+ WOLFSSH_CHANNEL * channel = NULL ;
726+ byte data [110 ];
727+ int result = 0 ;
728+ int ret ;
729+
730+ WMEMSET (data , 0xAB , sizeof (data ));
731+
732+ ctx = wolfSSH_CTX_new (WOLFSSH_ENDPOINT_SERVER , NULL );
733+ if (ctx == NULL )
734+ return -400 ;
735+ ssh = wolfSSH_new (ctx );
736+ if (ssh == NULL ) {
737+ wolfSSH_CTX_free (ctx );
738+ return -401 ;
739+ }
740+
741+ /* Window of 100 bytes, matching the input buffer size. */
742+ channel = ChannelNew (ssh , ID_CHANTYPE_SESSION , 100 , 100 );
743+ if (channel == NULL ) {
744+ wolfSSH_free (ssh );
745+ wolfSSH_CTX_free (ctx );
746+ return -402 ;
747+ }
748+
749+ /* NULL channel */
750+ ret = wolfSSH_TestChannelPutData (NULL , data , 10 );
751+ if (ret != WS_BAD_ARGUMENT ) {
752+ result = -403 ;
753+ goto done ;
754+ }
755+
756+ /* NULL data */
757+ ret = wolfSSH_TestChannelPutData (channel , NULL , 10 );
758+ if (ret != WS_BAD_ARGUMENT ) {
759+ result = -404 ;
760+ goto done ;
761+ }
762+
763+ /* dataSz exceeds windowSz: 101 > 100 */
764+ ret = wolfSSH_TestChannelPutData (channel , data , 101 );
765+ if (ret != WS_FATAL_ERROR ) {
766+ result = -405 ;
767+ goto done ;
768+ }
769+
770+ /* Valid write consuming half the window */
771+ ret = wolfSSH_TestChannelPutData (channel , data , 50 );
772+ if (ret != WS_SUCCESS ) {
773+ result = -406 ;
774+ goto done ;
775+ }
776+
777+ /* Remaining windowSz is 50; sending 51 must be rejected */
778+ ret = wolfSSH_TestChannelPutData (channel , data , 51 );
779+ if (ret != WS_FATAL_ERROR ) {
780+ result = -407 ;
781+ goto done ;
782+ }
783+
784+ done :
785+ ChannelDelete (channel , ctx -> heap );
786+ wolfSSH_free (ssh );
787+ wolfSSH_CTX_free (ctx );
788+ return result ;
789+ }
721790
722791/* Verify DoChannelRequest sends CHANNEL_SUCCESS for known types and
723792 * CHANNEL_FAILURE for unrecognized ones (RFC 4254 Section 5.4).
@@ -1138,6 +1207,9 @@ int wolfSSH_UnitTest(int argc, char** argv)
11381207 (unitResult == 0 ? "SUCCESS" : "FAILED" ));
11391208 testResult = testResult || unitResult ;
11401209#endif
1210+ unitResult = test_ChannelPutData ();
1211+ printf ("ChannelPutData: %s\n" , (unitResult == 0 ? "SUCCESS" : "FAILED" ));
1212+ testResult = testResult || unitResult ;
11411213#endif
11421214
11431215#ifdef WOLFSSH_KEYGEN
0 commit comments