aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorBrian Feldman <green@FreeBSD.org>1999-08-20 16:19:26 +0000
committerBrian Feldman <green@FreeBSD.org>1999-08-20 16:19:26 +0000
commitd2fed466acf0125a128a1bab495d205fb6a963b2 (patch)
treec974873c86e3d829c36282da5222a40701df2224 /bin
parentef2d1042102c9f7365c43ca546aa6454e0496644 (diff)
downloadsrc-d2fed466acf0125a128a1bab495d205fb6a963b2.tar.gz
src-d2fed466acf0125a128a1bab495d205fb6a963b2.zip
Finally: fix test -x as completely as possible.
Reviewed by: bde Reworked by: bde
Notes
Notes: svn path=/head/; revision=50087
Diffstat (limited to 'bin')
-rw-r--r--bin/test/test.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/bin/test/test.c b/bin/test/test.c
index 43a26aa219a8..e44f94bd28e3 100644
--- a/bin/test/test.c
+++ b/bin/test/test.c
@@ -12,7 +12,7 @@
#ifndef lint
static const char rcsid[] =
- "$Id: test.c,v 1.23 1999/08/16 09:44:09 sheldonh Exp $";
+ "$Id: test.c,v 1.24 1999/08/18 00:18:52 green Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -170,6 +170,13 @@ main(argc, argv)
argv[argc] = NULL;
}
+ /*
+ * We need to set our real user and group so that when we call
+ * access(2), it won't possibly return incorrect results.
+ */
+ (void)setgid(getegid());
+ (void)setuid(geteuid());
+
t_wp = &argv[1];
res = !oexpr(t_lex(*t_wp));
@@ -328,12 +335,15 @@ filstat(nm, mode)
case FILWR:
return access(nm, W_OK) == 0;
case FILEX:
- if (access(nm, X_OK) == 0) {
- if (getuid() == 0 && (s.st_mode & 0111) == 0)
- return 0;
- return 1;
- }
- return 1;
+ /*
+ * We cannot simply use access(2) for this specific case
+ * since it can always return false positives for root.
+ */
+ if (access(nm, X_OK) != 0)
+ return 0;
+ if (S_ISDIR(s.st_mode) || getuid() != 0)
+ return 1;
+ return (s.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0;
case FILEXIST:
return access(nm, F_OK) == 0;
case FILREG: