setgroups03: Fix running more iterations (-i 2)
PATCH 1/1 setgroups03: Fix running more iterations (-i 2)
When run the test with option "-i 2", test will fail and report "setgroups03.c:157: setgroups(65537) fails, Size is > sysconf(_SC_NGROUPS_MAX), errno=1, expected errno=22".
--- .../kernel/syscalls/setgroups/setgroups03.c | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/setgroups/setgroups03.c +23 -1
@@ -88,6 +88,7 @@ GID_T *groups_list; /* Array to hold gids for getgroups() */int setup1 ();/* setup function to test error EPERM */ void setup ();/* setup function for the test */ +void cleanup1 ();/* cleanup function for setup1 */ void cleanup ();/* cleanup function for the test */ struct test_case_t {/* test case struct. to hold ref. test cond's */
@@ -156,6 +157,9 @@ int main(int ac, char **av) gidsetsize, test_desc,TEST_ERRNO , Test_cases[i].exp_errno); } +if (Test_cases[i].setupfunc !=NULL ) { +cleanup1 (); + } } }
@@ -191,7 +195,7 @@ int setup1(void) {struct passwd *user_info;/* struct. to hold test user info */ -/* Switch to nobody user for correct error code collection */ +/* Switch to nobody user for correct error code collection */ ltpuser =getpwnam (nobody_uid);if (seteuid (ltpuser->pw_uid) ==-1 ) { tst_resm(TINFO, "setreuid failed to "
@@ -212,6 +216,24 @@ int setup1(void)return 0 ; } +void cleanup1 (void ) +{ +struct passwd *user_info; +if (seteuid (0 ) <0 ) +tst_brkm (TBROK , cleanup,"seteuid failed" ); + +if ((user_info =getpwnam ("root" )) ==NULL ) +tst_brkm (TBROK , cleanup,"getpwnam(2) of root Failed" ); + +if (!GID_SIZE_CHECK (user_info->pw_gid)) { +tst_brkm (TBROK , + cleanup, +"gid returned from getpwnam is too large for testing setgroups16" ); + } + + groups_list[0 ] = user_info->pw_gid; +} +/* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit.
--
2.17.1
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Zhao,
Quoted 3 lines
When run the test with option "-i 2", test will fail and report "setgroups03.c:157: setgroups(65537) fails, Size is >
sysconf(_SC_NGROUPS_MAX), errno=1, expected errno=22".
good point, thanks for addressing this.
Quoted 10 lines
Signed-off-by Zhao Gongyi <[email protected]>--- .../kernel/syscalls/setgroups/setgroups03.c | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)testcases/kernel/syscalls/setgroups/setgroups03.c +0
-0
testcases/kernel/syscalls/setgroups/setgroups03.c GID_T *groups_list; /* Array to hold gids for getgroups() */ · line 92
Quoted 5 lines
testcases/kernel/syscalls/setgroups/setgroups03.c +1
-0@@ -88,6 +88,7 @@ GID_T *groups_list; /* Array to hold gids for getgroups() */int setup1 ();/* setup function to test error EPERM */ void setup ();/* setup function for the test */ +void cleanup1 ();/* cleanup function for setup1 */ void cleanup ();/* cleanup function for the test */
This test really deserves porting to new API. cleanup() function is empty (thus we should actually delete it and use NULL instead of cleanup in tst_resm and other functions, but that'll be cleaned in new API rewrite) and there are other wrong parts (e.g. setup1() return only 0, but not 1 on failure) and really ugly style (useless comments).
Quoted 21 lines
testcases/kernel/syscalls/setgroups/setgroups03.c +4
-1struct test_case_t {/* test case struct. to hold ref. test cond's */ @@ -156,6 +157,9 @@ int main(int ac, char **av) gidsetsize, test_desc,TEST_ERRNO , Test_cases[i].exp_errno); } +if (Test_cases[i].setupfunc !=NULL ) { +cleanup1 (); + } } }@@ -191,7 +195,7 @@ int setup1(void) {struct passwd *user_info;/* struct. to hold test user info */ -/* Switch to nobody user for correct error code collection */ +/* Switch to nobody user for correct error code collection */ ltpuser =getpwnam (nobody_uid);if (seteuid (ltpuser->pw_uid) ==-1 ) { tst_resm(TINFO, "setreuid failed to "
testcases/kernel/syscalls/setgroups/setgroups03.c int setup1(void) · line 221
Quoted 6 lines
testcases/kernel/syscalls/setgroups/setgroups03.c +3
-0@@ -212,6 +216,24 @@ int setup1(void)return 0 ; } +void cleanup1 (void ) +{ +struct passwd *user_info;
nit: blank line here.
testcases/kernel/syscalls/setgroups/setgroups03.c int setup1(void) · line 223
Quoted 2 lines
testcases/kernel/syscalls/setgroups/setgroups03.c +2
-0+if (seteuid (0 ) <0 ) +tst_brkm (TBROK , cleanup,"seteuid failed" );
SAFE_SETEUID(cleanup, 0);
testcases/kernel/syscalls/setgroups/setgroups03.c int setup1(void) · line 226
Quoted 3 lines
testcases/kernel/syscalls/setgroups/setgroups03.c +3
-0+ +if ((user_info =getpwnam ("root" )) ==NULL ) +tst_brkm (TBROK , cleanup,"getpwnam(2) of root Failed" );
SAFE_GETPWNAM(cleanup, NULL)
testcases/kernel/syscalls/setgroups/setgroups03.c int setup1(void) · line 235
Quoted 9 lines
testcases/kernel/syscalls/setgroups/setgroups03.c +9
-0+ +if (!GID_SIZE_CHECK (user_info->pw_gid)) { +tst_brkm (TBROK , + cleanup, +"gid returned from getpwnam is too large for testing setgroups16" ); + } + + groups_list[0 ] = user_info->pw_gid; +}
Actually setup1() and cleanup1() could be single function if it takes uid_t euid parameter, because this part of setup1() should IMHO be SAFE_GETPWNAM():
if (seteuid(ltpuser->pw_uid) == -1) {
tst_resm(TINFO, "setreuid failed to "
"to set the effective uid to %d", ltpuser->pw_uid);
perror("setreuid");
}I'll send v2 under your name.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp