@@ -1331,13 +1331,15 @@ static int test_DoChannelRequest(void)
13311331 * request capture so the two tests can run independently in any order. */
13321332static byte s_authSvcCapture [256 ];
13331333static word32 s_authSvcCaptureSz = 0 ;
1334+ static word32 s_authSvcSendCount = 0 ;
13341335
13351336static int CaptureIoSendAuthSvc (WOLFSSH * ssh , void * buf , word32 sz , void * ctx )
13361337{
13371338 (void )ssh ; (void )ctx ;
13381339 s_authSvcCaptureSz = (sz < (word32 )sizeof (s_authSvcCapture ))
13391340 ? sz : (word32 )sizeof (s_authSvcCapture );
13401341 WMEMCPY (s_authSvcCapture , buf , s_authSvcCaptureSz );
1342+ s_authSvcSendCount ++ ;
13411343 return (int )sz ;
13421344}
13431345
@@ -1413,16 +1415,17 @@ static int test_DoUserAuthRequest_serviceName(void)
14131415 if (ctx == NULL ) return -500 ;
14141416 wolfSSH_SetIOSend (ctx , CaptureIoSendAuthSvc );
14151417
1416- ssh = wolfSSH_new (ctx );
1417- if (ssh == NULL ) { wolfSSH_CTX_free (ctx ); return -501 ; }
1418-
14191418 for (i = 0 ; i < (int )(sizeof (cases )/sizeof (cases [0 ])); i ++ ) {
14201419 byte buf [128 ];
14211420 word32 len = 0 , idx = 0 ;
14221421 word32 snsz = cases [i ].svcNameSz ;
14231422 int ret ;
14241423
1424+ ssh = wolfSSH_new (ctx );
1425+ if (ssh == NULL ) { result = -501 ; goto done ; }
1426+
14251427 s_authSvcCaptureSz = 0 ;
1428+ s_authSvcSendCount = 0 ;
14261429 WMEMSET (s_authSvcCapture , 0 , sizeof (s_authSvcCapture ));
14271430
14281431 /* username: "user" */
@@ -1449,11 +1452,18 @@ static int test_DoUserAuthRequest_serviceName(void)
14491452
14501453 ret = wolfSSH_TestDoUserAuthRequest (ssh , buf , len , & idx );
14511454
1455+ if (s_authSvcSendCount != 1 ) {
1456+ printf ("DoUserAuthRequest_svcName[%s]: expected 1 send, got %u\n" ,
1457+ cases [i ].label , s_authSvcSendCount );
1458+ result = -540 - i ;
1459+ goto done ;
1460+ }
1461+
14521462 if (ret != cases [i ].expectRet ) {
14531463 printf ("DoUserAuthRequest_svcName[%s]: ret=%d expected=%d\n" ,
14541464 cases [i ].label , ret , cases [i ].expectRet );
14551465 result = -502 - i ;
1456- break ;
1466+ goto done ;
14571467 }
14581468
14591469 /* MSGID_USERAUTH_FAILURE must be in the captured packet. */
@@ -1466,7 +1476,7 @@ static int test_DoUserAuthRequest_serviceName(void)
14661476 s_authSvcCaptureSz ,
14671477 capMsgId >= 0 ? capMsgId : 0 );
14681478 result = -520 - i ;
1469- break ;
1479+ goto done ;
14701480 }
14711481 }
14721482
@@ -1475,10 +1485,14 @@ static int test_DoUserAuthRequest_serviceName(void)
14751485 printf ("DoUserAuthRequest_svcName[%s]: idx=%u expected len=%u\n" ,
14761486 cases [i ].label , idx , len );
14771487 result = -510 - i ;
1478- break ;
1488+ goto done ;
14791489 }
1490+
1491+ wolfSSH_free (ssh );
1492+ ssh = NULL ;
14801493 }
14811494
1495+ done :
14821496 wolfSSH_free (ssh );
14831497 wolfSSH_CTX_free (ctx );
14841498 return result ;
0 commit comments