Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/c063 Add a few O_SEARCH tests, currently only...



details:   https://anonhg.NetBSD.org/src/rev/47aad81df6da
branches:  trunk
changeset: 744559:47aad81df6da
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Feb 06 12:18:06 2020 +0000

description:
Add a few O_SEARCH tests, currently only run on FreeBSD.
Patch from Kyle Evans.

diffstat:

 tests/lib/libc/c063/t_o_search.c |  78 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 74 insertions(+), 4 deletions(-)

diffs (118 lines):

diff -r e13a8f1a4867 -r 47aad81df6da tests/lib/libc/c063/t_o_search.c
--- a/tests/lib/libc/c063/t_o_search.c  Thu Feb 06 12:13:45 2020 +0000
+++ b/tests/lib/libc/c063/t_o_search.c  Thu Feb 06 12:18:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_o_search.c,v 1.8 2020/02/05 17:13:24 martin Exp $ */
+/*     $NetBSD: t_o_search.c,v 1.9 2020/02/06 12:18:06 martin Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,13 +29,14 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_o_search.c,v 1.8 2020/02/05 17:13:24 martin Exp $");
+__RCSID("$NetBSD: t_o_search.c,v 1.9 2020/02/06 12:18:06 martin Exp $");
 
 #include <atf-c.h>
 
-#include <sys/param.h>
+#include <sys/types.h>
 #include <sys/stat.h>
 
+#include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -50,7 +51,7 @@
  * until a decision is reached about the semantics of O_SEARCH and a
  * non-broken implementation is available.
  */
-#if (O_MASK & O_SEARCH) != 0
+#if defined(__FreeBSD__) || (O_MASK & O_SEARCH) != 0
 #define USE_O_SEARCH
 #endif
 
@@ -263,6 +264,70 @@
        ATF_REQUIRE(close(dfd) == 0);
 }
 
+#ifdef USE_O_SEARCH
+ATF_TC(o_search_nord);
+ATF_TC_HEAD(o_search_nord, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "See that openat succeeds with no read permission");
+       atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_nord, tc)
+{
+       int dfd, fd;
+
+       ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+       ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+       ATF_REQUIRE(close(fd) == 0);
+
+       ATF_REQUIRE(chmod(DIR, 0100) == 0);
+       ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
+
+       ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) != -1);
+
+       ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(o_search_getdents);
+ATF_TC_HEAD(o_search_getdents, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "See that O_SEARCH forbids getdents");
+}
+ATF_TC_BODY(o_search_getdents, tc)
+{
+       char buf[1024];
+       int dfd;
+
+       ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+       ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
+       ATF_REQUIRE(getdents(dfd, buf, sizeof(buf)) < 0);
+       ATF_REQUIRE(close(dfd) == 0);
+}
+
+ATF_TC(o_search_revokex);
+ATF_TC_HEAD(o_search_revokex, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "See that *at behaves after chmod -x");
+       atf_tc_set_md_var(tc, "require.user", "unprivileged");
+}
+ATF_TC_BODY(o_search_revokex, tc)
+{
+       int dfd, fd;
+       struct stat sb;
+
+       ATF_REQUIRE(mkdir(DIR, 0755) == 0);
+       ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
+       ATF_REQUIRE(close(fd) == 0);
+
+       ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
+
+       /* Drop permissions. The kernel must still not check the exec bit. */
+       ATF_REQUIRE(chmod(DIR, 0000) == 0);
+       ATF_REQUIRE(fstatat(dfd, BASEFILE, &sb, 0) == 0);
+
+       ATF_REQUIRE(close(dfd) == 0);
+}
+#endif /* USE_O_SEARCH */
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -277,6 +342,11 @@
        ATF_TP_ADD_TC(tp, o_search_unpriv_flag2);
 #endif
        ATF_TP_ADD_TC(tp, o_search_notdir);
+#ifdef USE_O_SEARCH
+       ATF_TP_ADD_TC(tp, o_search_nord);
+       ATF_TP_ADD_TC(tp, o_search_getdents);
+       ATF_TP_ADD_TC(tp, o_search_revokex);
+#endif
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index