@@ -1942,7 +1942,7 @@ static int test_AuthRaisePermissions_separateCallsSyscalls(void)
19421942 WOLFSSHD_AUTH * auth ;
19431943 int (* savedEgid )(WGID_T );
19441944 int (* savedEuid )(WUID_T );
1945- struct passwd * (* savedGetpwnam )(const char * );
1945+ struct passwd * (* savedGetpwnam )(const char * ) = NULL ;
19461946
19471947 conf = wolfSSHD_ConfigNew (NULL );
19481948 if (conf == NULL ) {
@@ -1996,7 +1996,7 @@ static int test_AuthRaisePermissions_gidFailSkipsUid(void)
19961996 WOLFSSHD_AUTH * auth ;
19971997 int (* savedEgid )(WGID_T );
19981998 int (* savedEuid )(WUID_T );
1999- struct passwd * (* savedGetpwnam )(const char * );
1999+ struct passwd * (* savedGetpwnam )(const char * ) = NULL ;
20002000
20012001 conf = wolfSSHD_ConfigNew (NULL );
20022002 if (conf == NULL ) {
@@ -2039,7 +2039,7 @@ static int test_AuthRaisePermissions_uidFail(void)
20392039 WOLFSSHD_AUTH * auth ;
20402040 int (* savedEgid )(WGID_T );
20412041 int (* savedEuid )(WUID_T );
2042- struct passwd * (* savedGetpwnam )(const char * );
2042+ struct passwd * (* savedGetpwnam )(const char * ) = NULL ;
20432043
20442044 conf = wolfSSHD_ConfigNew (NULL );
20452045 if (conf == NULL ) {
@@ -2083,14 +2083,19 @@ static int test_AuthSetGroups_ok(void)
20832083 WOLFSSHD_AUTH * auth = NULL ;
20842084 int (* savedGrouplist )(const char * , WGID_T , WGID_T * , int * );
20852085 int (* savedSetgroups )(int , const WGID_T * );
2086+ struct passwd * (* savedGetpwnam )(const char * ) = wsshd_getpwnam_cb ;
20862087
20872088 conf = wolfSSHD_ConfigNew (NULL );
20882089 if (conf == NULL )
20892090 ret = WS_FATAL_ERROR ;
20902091 if (ret == WS_SUCCESS ) {
2092+ InstallGetpwnamStub (& savedGetpwnam );
20912093 auth = wolfSSHD_AuthCreateUser (NULL , conf );
2092- if (auth == NULL )
2093- ret = WS_FATAL_ERROR ;
2094+ if (auth == NULL ) {
2095+ wsshd_getpwnam_cb = savedGetpwnam ;
2096+ wolfSSHD_ConfigFree (conf );
2097+ return WS_FATAL_ERROR ;
2098+ }
20942099 }
20952100
20962101 InstallGroupStubs (0 , & savedGrouplist , & savedSetgroups );
@@ -2120,6 +2125,7 @@ static int test_AuthSetGroups_ok(void)
21202125
21212126 wsshd_getgrouplist_cb = savedGrouplist ;
21222127 wsshd_setgroups_cb = savedSetgroups ;
2128+ wsshd_getpwnam_cb = savedGetpwnam ;
21232129 if (auth != NULL )
21242130 (void )wolfSSHD_AuthFreeUser (auth );
21252131 if (conf != NULL )
@@ -2136,14 +2142,19 @@ static int test_AuthSetGroups_setgroups_fail(void)
21362142 WOLFSSHD_AUTH * auth = NULL ;
21372143 int (* savedGrouplist )(const char * , WGID_T , WGID_T * , int * );
21382144 int (* savedSetgroups )(int , const WGID_T * );
2145+ struct passwd * (* savedGetpwnam )(const char * ) = wsshd_getpwnam_cb ;
21392146
21402147 conf = wolfSSHD_ConfigNew (NULL );
21412148 if (conf == NULL )
21422149 ret = WS_FATAL_ERROR ;
21432150 if (ret == WS_SUCCESS ) {
2151+ InstallGetpwnamStub (& savedGetpwnam );
21442152 auth = wolfSSHD_AuthCreateUser (NULL , conf );
2145- if (auth == NULL )
2146- ret = WS_FATAL_ERROR ;
2153+ if (auth == NULL ) {
2154+ wsshd_getpwnam_cb = savedGetpwnam ;
2155+ wolfSSHD_ConfigFree (conf );
2156+ return WS_FATAL_ERROR ;
2157+ }
21472158 }
21482159
21492160 InstallGroupStubs (-1 , & savedGrouplist , & savedSetgroups );
@@ -2156,6 +2167,7 @@ static int test_AuthSetGroups_setgroups_fail(void)
21562167
21572168 wsshd_getgrouplist_cb = savedGrouplist ;
21582169 wsshd_setgroups_cb = savedSetgroups ;
2170+ wsshd_getpwnam_cb = savedGetpwnam ;
21592171 if (auth != NULL )
21602172 (void )wolfSSHD_AuthFreeUser (auth );
21612173 if (conf != NULL )
@@ -2172,14 +2184,19 @@ static int test_AuthSetGroups_getgrouplist_fail(void)
21722184 WOLFSSHD_AUTH * auth = NULL ;
21732185 int (* savedGrouplist )(const char * , WGID_T , WGID_T * , int * );
21742186 int (* savedSetgroups )(int , const WGID_T * );
2187+ struct passwd * (* savedGetpwnam )(const char * ) = wsshd_getpwnam_cb ;
21752188
21762189 conf = wolfSSHD_ConfigNew (NULL );
21772190 if (conf == NULL )
21782191 ret = WS_FATAL_ERROR ;
21792192 if (ret == WS_SUCCESS ) {
2193+ InstallGetpwnamStub (& savedGetpwnam );
21802194 auth = wolfSSHD_AuthCreateUser (NULL , conf );
2181- if (auth == NULL )
2182- ret = WS_FATAL_ERROR ;
2195+ if (auth == NULL ) {
2196+ wsshd_getpwnam_cb = savedGetpwnam ;
2197+ wolfSSHD_ConfigFree (conf );
2198+ return WS_FATAL_ERROR ;
2199+ }
21832200 }
21842201
21852202 InstallGroupStubs (0 , & savedGrouplist , & savedSetgroups );
@@ -2194,6 +2211,7 @@ static int test_AuthSetGroups_getgrouplist_fail(void)
21942211
21952212 wsshd_getgrouplist_cb = savedGrouplist ;
21962213 wsshd_setgroups_cb = savedSetgroups ;
2214+ wsshd_getpwnam_cb = savedGetpwnam ;
21972215 if (auth != NULL )
21982216 (void )wolfSSHD_AuthFreeUser (auth );
21992217 if (conf != NULL )
0 commit comments