diff --git a/coreutils/test.c b/coreutils/test.c index 96462d3a2..ad777953f 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -426,7 +426,7 @@ struct test_statics { /* set only by check_operator(), either to bogus struct * or points to matching operator_t struct. Never NULL. */ const struct operator_t *last_operator; - struct cached_groupinfo groupinfo; + struct cached_groupinfo *groupinfo; #if BASH_TEST2 bool bash_test2; #endif @@ -447,7 +447,6 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics; XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \ } while (0) #define DEINIT_S() do { \ - free(groupinfo.supplementary_array); \ free(test_ptr_to_statics); \ } while (0) @@ -642,7 +641,7 @@ static int is_a_group_member(gid_t gid) if (gid == getgid() || gid == getegid()) return 1; - return is_in_supplementary_groups(&groupinfo, gid); + return is_in_supplementary_groups(groupinfo, gid); } /* @@ -878,7 +877,7 @@ static number_t primary(enum token n) } -int test_main(int argc, char **argv) +int FAST_FUNC test_main2(struct cached_groupinfo *pgroupinfo, int argc, char **argv) { int res; const char *arg0; @@ -911,6 +910,7 @@ int test_main(int argc, char **argv) /* We must do DEINIT_S() prior to returning */ INIT_S(); + groupinfo = pgroupinfo; #if BASH_TEST2 bash_test2 = bt2; @@ -1013,3 +1013,16 @@ int test_main(int argc, char **argv) DEINIT_S(); return res; } + +int test_main(int argc, char **argv) +{ + struct cached_groupinfo info; + int r; + + info.ngroups = 0; + info.supplementary_array = NULL; + r = test_main2(&info, argc, argv); + free(info.supplementary_array); + + return r; +} diff --git a/include/libbb.h b/include/libbb.h index 99bbf623b..8748464ed 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1550,6 +1550,7 @@ int test_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE #endif ; +int FAST_FUNC test_main2(struct cached_groupinfo *pgroupinfo, int argc, char **argv); int kill_main(int argc, char **argv) #if ENABLE_KILL || ENABLE_KILLALL || ENABLE_KILLALL5 MAIN_EXTERNALLY_VISIBLE diff --git a/shell/ash.c b/shell/ash.c index fa57511a7..a6bb9894c 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10175,8 +10175,7 @@ static int FAST_FUNC echocmd(int argc, char **argv) { return echo_main(argc, a static int FAST_FUNC printfcmd(int argc, char **argv) { return printf_main(argc, argv); } #endif #if ENABLE_ASH_TEST || BASH_TEST2 -static int FAST_FUNC testcmd(int argc, char **argv) { return test_main(argc, argv); } -// TODO: pass &ngroups and &group_array addresses to test_main to use cached supplementary groups +static int FAST_FUNC testcmd(int argc, char **argv) { return test_main2(&groupinfo, argc, argv); } #endif #if ENABLE_ASH_SLEEP static int FAST_FUNC sleepcmd(int argc, char **argv) { return sleep_main(argc, argv); }