summaryrefslogtreecommitdiffstats
path: root/bin/test
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>1999-08-20 16:19:26 +0000
committergreen <green@FreeBSD.org>1999-08-20 16:19:26 +0000
commit124c84f339cbf203da9780081c1f02e667f1447a (patch)
treee359cde48b998daee3528bffbbb0bb4d1b13e879 /bin/test
parent23b2b75085929e9d312282bcfdaf8488d4b1a6c3 (diff)
downloadFreeBSD-src-124c84f339cbf203da9780081c1f02e667f1447a.zip
FreeBSD-src-124c84f339cbf203da9780081c1f02e667f1447a.tar.gz
Finally: fix test -x as completely as possible.
Reviewed by: bde Reworked by: bde
Diffstat (limited to 'bin/test')
-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 43a26aa..e44f94b 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:
OpenPOWER on IntegriCloud