@@ -1502,6 +1502,20 @@ static void test_wolfSSH_agent_signrequest_success(void)
15021502#if defined(WOLFSSH_SFTP ) && !defined(NO_WOLFSSH_CLIENT ) && \
15031503 !defined(SINGLE_THREADED )
15041504
1505+ /* A peer that is already gone at shutdown is not a test failure. The send path
1506+ * reports the reset as the return value; the recv path returns the generic
1507+ * WS_ERROR and stashes the specific code in wolfSSH_get_error. */
1508+ static int AbsorbBenignReset (WOLFSSH * ssh , int ret )
1509+ {
1510+ if (ret == WS_SOCKET_ERROR_E ||
1511+ (ret == WS_ERROR &&
1512+ wolfSSH_get_error (ssh ) == WS_SOCKET_ERROR_E )) {
1513+ ret = WS_SUCCESS ;
1514+ }
1515+
1516+ return ret ;
1517+ }
1518+
15051519byte userPassword [256 ];
15061520
15071521static int sftpUserAuth (byte authType , WS_UserAuthData * authData , void * ctx )
@@ -1635,10 +1649,8 @@ static void test_wolfSSH_SFTP_SendReadPacket(void)
16351649 argsCount = 0 ;
16361650 args [argsCount ++ ] = "." ;
16371651 args [argsCount ++ ] = "-1" ;
1638- #ifndef USE_WINDOWS_API
16391652 args [argsCount ++ ] = "-p" ;
16401653 args [argsCount ++ ] = "0" ;
1641- #endif
16421654 ser .argv = (char * * )args ;
16431655 ser .argc = argsCount ;
16441656 ser .signal = & ready ;
@@ -1819,11 +1831,7 @@ static void test_wolfSSH_SFTP_SendReadPacket(void)
18191831 wolfSSH_worker (ssh , NULL );
18201832 }
18211833
1822- argsCount = wolfSSH_shutdown (ssh );
1823- if (argsCount == WS_SOCKET_ERROR_E ) {
1824- /* If the socket is closed on shutdown, peer is gone, this is OK. */
1825- argsCount = WS_SUCCESS ;
1826- }
1834+ argsCount = AbsorbBenignReset (ssh , wolfSSH_shutdown (ssh ));
18271835
18281836#if DEFAULT_HIGHWATER_MARK < 8000
18291837 if (argsCount == WS_REKEYING ) {
@@ -1845,6 +1853,7 @@ static void test_wolfSSH_SFTP_SendReadPacket(void)
18451853 k_sleep (Z_TIMEOUT_TICKS (100 ));
18461854#endif
18471855 ThreadJoin (serThread );
1856+ FreeTcpReady (& ready );
18481857}
18491858
18501859
@@ -1905,10 +1914,8 @@ static void test_wolfSSH_SFTP_PartialSend(void)
19051914 argsCount = 0 ;
19061915 args [argsCount ++ ] = "." ;
19071916 args [argsCount ++ ] = "-1" ;
1908- #ifndef USE_WINDOWS_API
19091917 args [argsCount ++ ] = "-p" ;
19101918 args [argsCount ++ ] = "0" ;
1911- #endif
19121919 ser .argv = (char * * )args ;
19131920 ser .argc = argsCount ;
19141921 ser .signal = & ready ;
@@ -2094,10 +2101,7 @@ static void test_wolfSSH_SFTP_PartialSend(void)
20942101 wolfSSH_worker (ssh , NULL );
20952102 }
20962103
2097- argsCount = wolfSSH_shutdown (ssh );
2098- if (argsCount == WS_SOCKET_ERROR_E ) {
2099- argsCount = WS_SUCCESS ;
2100- }
2104+ argsCount = AbsorbBenignReset (ssh , wolfSSH_shutdown (ssh ));
21012105#if DEFAULT_HIGHWATER_MARK < 8000
21022106 if (argsCount == WS_REKEYING ) {
21032107 argsCount = WS_SUCCESS ;
@@ -2114,6 +2118,7 @@ static void test_wolfSSH_SFTP_PartialSend(void)
21142118 k_sleep (Z_TIMEOUT_TICKS (100 ));
21152119#endif
21162120 ThreadJoin (serThread );
2121+ FreeTcpReady (& ready );
21172122#endif /* WOLFSSH_TEST_INTERNAL */
21182123}
21192124
@@ -2145,10 +2150,8 @@ static void sftp_rekey_test(int nonBlock)
21452150 argsCount = 0 ;
21462151 args [argsCount ++ ] = "." ;
21472152 args [argsCount ++ ] = "-1" ;
2148- #ifndef USE_WINDOWS_API
21492153 args [argsCount ++ ] = "-p" ;
21502154 args [argsCount ++ ] = "0" ;
2151- #endif
21522155 ser .argv = (char * * )args ;
21532156 ser .argc = argsCount ;
21542157 ser .signal = & ready ;
@@ -2232,9 +2235,7 @@ static void sftp_rekey_test(int nonBlock)
22322235 * before the WS_REKEYING fixup below could otherwise mask it. The loop cap
22332236 * is one above the assert threshold to leave last-iteration headroom. */
22342237 AssertIntLE (tries , SFTP_REKEY_MAX_TRIES );
2235- if (argsCount == WS_SOCKET_ERROR_E ) {
2236- argsCount = WS_SUCCESS ;
2237- }
2238+ argsCount = AbsorbBenignReset (ssh , argsCount );
22382239#if DEFAULT_HIGHWATER_MARK < 8000
22392240 if (argsCount == WS_REKEYING ) {
22402241 /* in cases where highwater mark is really small a re-key could happen */
@@ -2252,6 +2253,7 @@ static void sftp_rekey_test(int nonBlock)
22522253 k_sleep (Z_TIMEOUT_TICKS (100 ));
22532254#endif
22542255 ThreadJoin (serThread );
2256+ FreeTcpReady (& ready );
22552257}
22562258
22572259static void test_wolfSSH_SFTP_ReKey (void )
@@ -2430,10 +2432,8 @@ static void test_wolfSSH_SFTP_Confinement(void)
24302432 argsCount = 0 ;
24312433 args [argsCount ++ ] = "." ;
24322434 args [argsCount ++ ] = "-1" ;
2433- #ifndef USE_WINDOWS_API
24342435 args [argsCount ++ ] = "-p" ;
24352436 args [argsCount ++ ] = "0" ;
2436- #endif
24372437 ser .argv = (char * * )args ;
24382438 ser .argc = argsCount ;
24392439 ser .signal = & ready ;
@@ -2606,10 +2606,7 @@ static void test_wolfSSH_SFTP_Confinement(void)
26062606 while (wolfSSH_get_error (ssh ) == WS_REKEYING )
26072607 wolfSSH_worker (ssh , NULL );
26082608
2609- ret = wolfSSH_shutdown (ssh );
2610- if (ret == WS_SOCKET_ERROR_E ) {
2611- ret = WS_SUCCESS ;
2612- }
2609+ ret = AbsorbBenignReset (ssh , wolfSSH_shutdown (ssh ));
26132610#if DEFAULT_HIGHWATER_MARK < 8000
26142611 if (ret == WS_REKEYING ) {
26152612 ret = WS_SUCCESS ;
@@ -2624,6 +2621,7 @@ static void test_wolfSSH_SFTP_Confinement(void)
26242621 k_sleep (Z_TIMEOUT_TICKS (100 ));
26252622#endif
26262623 ThreadJoin (serThread );
2624+ FreeTcpReady (& ready );
26272625
26282626 /* remove staged targets; escMkdir/escDest only exist if confinement
26292627 * leaked, and inJailDir only if the positive-case RMDIR did not run, so
@@ -2945,10 +2943,8 @@ static void scp_rekey_test(int nonBlock, int toServer)
29452943 argsCount = 0 ;
29462944 args [argsCount ++ ] = "." ;
29472945 args [argsCount ++ ] = "-1" ;
2948- #ifndef USE_WINDOWS_API
29492946 args [argsCount ++ ] = "-p" ;
29502947 args [argsCount ++ ] = "0" ;
2951- #endif
29522948 ser .argv = (char * * )args ;
29532949 ser .argc = argsCount ;
29542950 ser .signal = & ready ;
@@ -3043,6 +3039,7 @@ static void scp_rekey_test(int nonBlock, int toServer)
30433039 wolfSSH_free (ssh );
30443040 wolfSSH_CTX_free (ctx );
30453041 ThreadJoin (serThread );
3042+ FreeTcpReady (& ready );
30463043
30473044 /* verify the transferred file matches the source once the server is done */
30483045 AssertIntEQ (scpFilesMatch (verifyName , fileData , SCP_REKEY_FILE_SZ ), 0 );
@@ -3759,10 +3756,8 @@ static void test_wolfSSH_KeyboardInteractive(void)
37593756 args [argsCount ++ ] = "-1" ;
37603757 args [argsCount ++ ] = "-i" ;
37613758 args [argsCount ++ ] = "test:test" ;
3762- #ifndef USE_WINDOWS_API
37633759 args [argsCount ++ ] = "-p" ;
37643760 args [argsCount ++ ] = "0" ;
3765- #endif
37663761 ser .argv = (char * * )args ;
37673762 ser .argc = argsCount ;
37683763 ser .signal = & ready ;
@@ -3775,11 +3770,7 @@ static void test_wolfSSH_KeyboardInteractive(void)
37753770 AssertNotNull (ssh );
37763771
37773772
3778- argsCount = wolfSSH_shutdown (ssh );
3779- if (argsCount == WS_SOCKET_ERROR_E ) {
3780- /* If the socket is closed on shutdown, peer is gone, this is OK. */
3781- argsCount = WS_SUCCESS ;
3782- }
3773+ argsCount = AbsorbBenignReset (ssh , wolfSSH_shutdown (ssh ));
37833774
37843775#if DEFAULT_HIGHWATER_MARK < 8000
37853776 if (argsCount == WS_REKEYING ) {
@@ -3801,6 +3792,7 @@ static void test_wolfSSH_KeyboardInteractive(void)
38013792 k_sleep (Z_TIMEOUT_TICKS (100 ));
38023793#endif
38033794 ThreadJoin (serThread );
3795+ FreeTcpReady (& ready );
38043796}
38053797
38063798#else /* WOLFSSH_SFTP && !NO_WOLFSSH_CLIENT && !SINGLE_THREADED */
@@ -3819,6 +3811,8 @@ int wolfSSH_ApiTest(int argc, char** argv)
38193811#ifdef WOLFSSH_TEST_BLOCK
38203812 return 77 ;
38213813#else
3814+ WSTARTTCP ();
3815+
38223816 AssertIntEQ (wolfSSH_Init (), WS_SUCCESS );
38233817
38243818 #if defined(FIPS_VERSION_GE ) && FIPS_VERSION_GE (5 ,2 )
0 commit comments