aboutsummaryrefslogtreecommitdiff
path: root/coreutils/test.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2024-10-07 07:28:44 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2024-10-07 07:28:44 +0200
commit96b0607302500ed201a7816282efbaa8f990aa33 (patch)
tree06356b47fe5be44acad2e5b947e23e5411f9d33a /coreutils/test.c
parentd26e9587252fdf4774a05e351b86d3a18c46384e (diff)
downloadbusybox-w32-96b0607302500ed201a7816282efbaa8f990aa33.tar.gz
busybox-w32-96b0607302500ed201a7816282efbaa8f990aa33.tar.bz2
busybox-w32-96b0607302500ed201a7816282efbaa8f990aa33.zip
ash: cache more of uid/gid syscalls
Testcase: setuidgid 1:1 strace ash -c 'test -x TODO; test -x TODO; echo $?' should show that second "test -x" does not query ids again. function old new delta ash_main 1236 1256 +20 get_cached_euid - 19 +19 get_cached_egid - 19 +19 test_main 56 72 +16 test_exec 119 135 +16 is_in_supplementary_groups 52 57 +5 nexpr 718 702 -16 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 4/1 up/down: 95/-16) Total: 79 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/test.c')
-rw-r--r--coreutils/test.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index ad777953f..6085d6663 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -638,7 +638,7 @@ static int binop(void)
638static int is_a_group_member(gid_t gid) 638static int is_a_group_member(gid_t gid)
639{ 639{
640 /* Short-circuit if possible, maybe saving a call to getgroups(). */ 640 /* Short-circuit if possible, maybe saving a call to getgroups(). */
641 if (gid == getgid() || gid == getegid()) 641 if (gid == get_cached_egid(&groupinfo->egid))
642 return 1; 642 return 1;
643 643
644 return is_in_supplementary_groups(groupinfo, gid); 644 return is_in_supplementary_groups(groupinfo, gid);
@@ -656,15 +656,16 @@ static int test_st_mode(struct stat *st, int mode)
656 656
657//TODO if (mode == X_OK) { 657//TODO if (mode == X_OK) {
658// /* Do we already know with no extra syscalls? */ 658// /* Do we already know with no extra syscalls? */
659// if (!S_ISREG(st->st_mode)) 659// //if (!S_ISREG(st->st_mode))
660// return 0; /* not a regular file */ 660// // return 0; /* not a regular file */
661// // ^^^ bash does not check this
661// if ((st->st_mode & ANY_IX) == 0) 662// if ((st->st_mode & ANY_IX) == 0)
662// return 0; /* no one can execute */ 663// return 0; /* no one can execute */
663// if ((st->st_mode & ANY_IX) == ANY_IX) 664// if ((st->st_mode & ANY_IX) == ANY_IX)
664// return 1; /* anyone can execute */ 665// return 1; /* anyone can execute */
665// } 666// }
666 667
667 euid = geteuid(); 668 euid = get_cached_euid(&groupinfo->euid);
668 if (euid == 0) { 669 if (euid == 0) {
669 /* Root can read or write any file. */ 670 /* Root can read or write any file. */
670 if (mode != X_OK) 671 if (mode != X_OK)
@@ -1019,6 +1020,8 @@ int test_main(int argc, char **argv)
1019 struct cached_groupinfo info; 1020 struct cached_groupinfo info;
1020 int r; 1021 int r;
1021 1022
1023 info.euid = -1;
1024 info.egid = -1;
1022 info.ngroups = 0; 1025 info.ngroups = 0;
1023 info.supplementary_array = NULL; 1026 info.supplementary_array = NULL;
1024 r = test_main2(&info, argc, argv); 1027 r = test_main2(&info, argc, argv);