aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile4
-rw-r--r--tests/Makefile.am123
-rw-r--r--tests/atlocal.in27
-rw-r--r--tests/fchmod-0.c35
-rwxr-xr-xtests/fchmod-1.sh18
-rwxr-xr-xtests/fchmod-2.sh11
-rw-r--r--tests/fchmod.at2
-rw-r--r--tests/fchown-0.c34
-rwxr-xr-xtests/fchown-1.sh18
-rwxr-xr-xtests/fchown-2.sh11
-rw-r--r--tests/fchown.at2
-rw-r--r--tests/fork-follow_static_tst.c1
-rw-r--r--tests/fork-follow_tst.c34
-rw-r--r--tests/get-group.c4
-rw-r--r--tests/get-user.c4
-rwxr-xr-xtests/git-bisector.sh15
-rw-r--r--tests/libsigsegv_tst.c2
-rw-r--r--tests/local.at2
-rw-r--r--tests/local.mk150
-rw-r--r--tests/lremovexattr-0.c15
-rw-r--r--tests/lsetxattr-0.c24
-rwxr-xr-xtests/lutimes-1.sh9
-rw-r--r--tests/lutimes.at1
-rw-r--r--tests/malloc_hooked_tst.c2
-rw-r--r--tests/removexattr-0.c15
-rwxr-xr-xtests/removexattr-1.sh13
-rw-r--r--tests/removexattr.at1
-rw-r--r--tests/renameat2-0.c22
-rwxr-xr-xtests/renameat2-1.sh8
-rwxr-xr-xtests/renameat2-2.sh12
-rwxr-xr-xtests/renameat2-3.sh11
-rw-r--r--tests/renameat2.at3
-rwxr-xr-xtests/script-1.sh7
-rwxr-xr-x[-rw-r--r--]tests/script-14.sh0
-rwxr-xr-x[-rw-r--r--]tests/script-15.sh0
-rwxr-xr-xtests/script-16.sh2
-rwxr-xr-xtests/script-17.sh23
-rwxr-xr-xtests/script-2.sh2
-rwxr-xr-xtests/script-3.sh2
-rwxr-xr-xtests/script-8.sh3
-rw-r--r--tests/script.at3
-rw-r--r--tests/setxattr-0.c24
-rwxr-xr-xtests/setxattr-1.sh13
-rw-r--r--tests/setxattr.at1
-rw-r--r--tests/test-skel-0.c6
-rw-r--r--tests/tests.h1
-rwxr-xr-xtests/trace-02
-rw-r--r--tests/trace-memory_static_tst.c4
-rw-r--r--tests/utimensat64-0.c3
-rwxr-xr-xtests/utimensat64-1.sh9
-rw-r--r--tests/utimensat64.at1
-rw-r--r--tests/utimensat64_static-0.c1
-rwxr-xr-xtests/utimensat64_static-1.sh10
-rw-r--r--tests/utimensat64_static.at1
-rwxr-xr-xtests/xattr-07
55 files changed, 614 insertions, 144 deletions
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..2eed23e
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,4 @@
+# Helper for developers.
+all: tests ;
+clean: clean-checkPROGRAMS ; rm -f *.o *.l[ao] .libs/*
+%: ; $(MAKE) -C .. $@
diff --git a/tests/Makefile.am b/tests/Makefile.am
deleted file mode 100644
index 3baf5b1..0000000
--- a/tests/Makefile.am
+++ /dev/null
@@ -1,123 +0,0 @@
-AT_FILES = $(wildcard $(srcdir)/*.at)
-TESTSUITE = $(srcdir)/testsuite
-DISTCLEANFILES = atconfig
-EXTRA_DIST = atlocal.in package.m4.in $(AT_FILES) $(TESTSUITE) \
- test-skel-0.c \
- tests.h
-
-AM_CPPFLAGS = -I$(top_srcdir) $(SANDBOX_DEFINES)
-
-check_PROGRAMS = \
- get-group \
- get-user \
- sb_true \
- sb_true_static \
- \
- access-0 \
- chmod-0 \
- chown-0 \
- creat-0 \
- creat64-0 \
- execv-0 \
- execvp-0 \
- faccessat-0 \
- fchmodat-0 \
- fchownat-0 \
- fopen-0 \
- fopen64-0 \
- futimesat-0 \
- lchown-0 \
- link-0 \
- linkat-0 \
- linkat_static-0 \
- lutimes-0 \
- mkdtemp-0 \
- mkdir-0 \
- mkdir_static-0 \
- mkdirat-0 \
- mkfifo-0 \
- mkfifoat-0 \
- mknod-0 \
- mknodat-0 \
- mkostemp-0 \
- mkostemp64-0 \
- mkostemps-0 \
- mkostemps64-0 \
- mkstemp-0 \
- mkstemp64-0 \
- mkstemps-0 \
- mkstemps64-0 \
- open-0 \
- open_static-0 \
- open64-0 \
- openat-0 \
- openat_static-0 \
- openat64-0 \
- opendir-0 \
- remove-0 \
- rename-0 \
- renameat-0 \
- rmdir-0 \
- signal_static-0 \
- symlink-0 \
- symlinkat-0 \
- truncate-0 \
- truncate64-0 \
- unlink-0 \
- unlink_static-0 \
- unlinkat-0 \
- utime-0 \
- utimensat-0 \
- utimensat_static-0 \
- utimes-0 \
- vfork-0 \
- \
- getcwd-gnulib_tst \
- libsigsegv_tst \
- malloc_hooked_tst \
- malloc_mmap_tst \
- pipe-fork_tst \
- pipe-fork_static_tst \
- sb_printf_tst \
- sigsuspend-zsh_tst \
- sigsuspend-zsh_static_tst \
- trace-memory_static_tst
-
-dist_check_SCRIPTS = \
- $(wildcard $(srcdir)/*-[0-9]*.sh) \
- malloc-0 \
- script-0 \
- trace-0
-
-AM_LDFLAGS = `expr $@ : .*_static >/dev/null && echo -all-static`
-
-sb_printf_tst_CFLAGS = -I$(top_srcdir)/libsbutil -I$(top_srcdir)/libsbutil/include
-sb_printf_tst_LDADD = $(top_builddir)/libsbutil/libsbutil.la
-
-malloc_hooked_tst_LDFLAGS = $(AM_LDFLAGS) -pthread
-
-if HAVE_LIBSIGSEGV
-libsigsegv_tst_LDADD = -lsigsegv
-endif
-
-TESTSUITEFLAGS = --jobs=`getconf _NPROCESSORS_ONLN || echo 1`
-
-check-local: atconfig atlocal $(TESTSUITE)
- $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='src:tests' $(TESTSUITEFLAGS)
-
-installcheck-local: atconfig atlocal $(TESTSUITE)
- $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='src:tests:$(bindir)' $(TESTSUITEFLAGS)
-
-clean-local:
- test ! -f '$(TESTSUITE)' || \
- $(SHELL) '$(TESTSUITE)' --clean
-
-AUTOTEST = $(AUTOM4TE) --language=autotest
-$(TESTSUITE): $(AT_FILES) testsuite.list.at
- $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
- mv $@.tmp $@
-
-testsuite.list.at: $(AT_FILES)
- ( echo "dnl DO NOT EDIT: GENERATED BY MAKEFILE.AM"; \
- $(GREP) -l -e '^SB_CHECK' -e '^AT_CHECK' $(AT_FILES) | LC_ALL=C sort | \
- $(SED) -e 's:^[.]/:sb_inc([:' -e 's:[.]at$$:]):' ) > $@
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 91b41b2..adf3bad 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -24,5 +24,32 @@ export SANDBOX_VERBOSE=0
# If the terminal has this flag set, the tests get all messed up.
stty -tostop 2>/dev/null || :
+# Some tests want this internal path.
+for devfd in /proc/self/fd /dev/fd ; do
+ [ -e "${devfd}" ] && break
+done
+
+# GNU make likes to leak fds when using jobservers (i.e. using -j).
+case "${MAKEFLAGS}" in
+*--jobserver-auth=*)
+ flags=${MAKEFLAGS#*--jobserver-auth=}
+ flags=${flags%% *}
+ for fd in $(echo "${flags}" | tr ',' ' ') ; do
+ if [ -e "${devfd}/${fd}" ] ; then
+ eval "exec ${fd}>&-"
+ fi
+ done
+ ;;
+esac
+
+# Figure out currently YAMA ptrace_scope restriction level.
+at_yama_ptrace_scope=$(cat /proc/sys/kernel/yama/ptrace_scope 2>/dev/null || echo 0)
+if [ ${at_yama_ptrace_scope} -gt 0 ] ; then
+ if [ "$(id -u)" -eq 0 ] ; then
+ at_yama_ptrace_scope=0
+ fi
+fi
+export at_yama_ptrace_scope
+
# This script must finish with ($? == 0) else the autotest runner gets upset.
:
diff --git a/tests/fchmod-0.c b/tests/fchmod-0.c
new file mode 100644
index 0000000..de0c237
--- /dev/null
+++ b/tests/fchmod-0.c
@@ -0,0 +1,35 @@
+/*
+ * https://bugs.gentoo.org/599706
+ *
+ */
+
+#include "headers.h"
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2)
+ return -2;
+
+ int mode = 0;
+ sscanf(argv[1], "%i", &mode);
+ /* The sandbox catches this:
+ *
+ * int fd = open(argv[2], O_RDWR);
+ *
+ * And it /should/ catch this:
+ *
+ * int fd = open(argv[2], O_RDONLY);
+ *
+ * ...but the latter only works when /proc/self/fd/%i
+ * is available.
+ *
+ */
+#ifdef SANDBOX_PROC_SELF_FD
+ int fd = open(argv[2], O_RDONLY);
+#else
+ int fd = open(argv[2], O_RDWR);
+#endif
+ int fchmod_result = fchmod(fd, (mode_t)mode);
+ close(fd);
+ return fchmod_result;
+}
diff --git a/tests/fchmod-1.sh b/tests/fchmod-1.sh
new file mode 100755
index 0000000..140d84f
--- /dev/null
+++ b/tests/fchmod-1.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# https://bugs.gentoo.org/599706
+#
+
+addwrite $PWD
+rm -f deny || exit 1
+touch deny || exit 1
+adddeny $PWD/deny
+
+# The sandbox doesn't log anything when it returns a junk file
+# descriptor? It doesn't look like we can test the contents of
+# sandbox.log here... instead, we just have to count on fchmod
+# failing, which it does if you use O_RDWR, and it *should* if you use
+# O_RDONLY (because that won't stop the change of permissions).
+fchmod-0 $(stat --format='%#04a' $PWD/deny) $PWD/deny && exit 1
+
+exit 0
diff --git a/tests/fchmod-2.sh b/tests/fchmod-2.sh
new file mode 100755
index 0000000..96d7cc9
--- /dev/null
+++ b/tests/fchmod-2.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+#
+# Ensure that fchmod() doesn't trigger spurious violations in the most
+# basic of cases.
+#
+addwrite $PWD
+
+# This should not trigger a violation.
+rm -f file
+touch file
+fchmod-0 0644 file || exit 1
diff --git a/tests/fchmod.at b/tests/fchmod.at
new file mode 100644
index 0000000..d364b4b
--- /dev/null
+++ b/tests/fchmod.at
@@ -0,0 +1,2 @@
+SB_CHECK(1)
+SB_CHECK(2)
diff --git a/tests/fchown-0.c b/tests/fchown-0.c
new file mode 100644
index 0000000..7fdca73
--- /dev/null
+++ b/tests/fchown-0.c
@@ -0,0 +1,34 @@
+/*
+ * https://bugs.gentoo.org/599706
+ *
+ */
+
+#include "headers.h"
+
+int main(int argc, char *argv[])
+{
+ if (argc < 3)
+ return -2;
+
+ uid_t uid = atoi(argv[1]);
+ gid_t gid = atoi(argv[2]);
+ /* The sandbox catches this:
+ *
+ * int fd = open(argv[3], O_RDWR);
+ *
+ * And it /should/ catch this:
+ *
+ * int fd = open(argv[3], O_RDONLY);
+ *
+ * ...but the latter only works when /proc/self/fd/%i
+ * is available.
+ */
+#ifdef SANDBOX_PROC_SELF_FD
+ int fd = open(argv[3], O_RDONLY);
+#else
+ int fd = open(argv[3], O_RDWR);
+#endif
+ int fchown_result = fchown(fd, uid, gid);
+ close(fd);
+ return fchown_result;
+}
diff --git a/tests/fchown-1.sh b/tests/fchown-1.sh
new file mode 100755
index 0000000..6c1178e
--- /dev/null
+++ b/tests/fchown-1.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# https://bugs.gentoo.org/599706
+#
+
+addwrite $PWD
+rm -f deny || exit 1
+touch deny || exit 1
+adddeny $PWD/deny
+
+# The sandbox doesn't log anything when it returns a junk file
+# descriptor? It doesn't look like we can test the contents of
+# sandbox.log here... instead, we just have to count on fchown
+# failing, which it does if you use O_RDWR, and it *should* if you use
+# O_RDONLY (because that won't stop the change of ownership).
+fchown-0 ${SB_UID} ${SB_GID} $PWD/deny && exit 1
+
+exit 0
diff --git a/tests/fchown-2.sh b/tests/fchown-2.sh
new file mode 100755
index 0000000..dedfbe4
--- /dev/null
+++ b/tests/fchown-2.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+#
+# Ensure that fchown() doesn't trigger spurious violations in the most
+# basic of cases.
+#
+addwrite $PWD
+
+# This should not trigger a violation.
+rm -f file
+touch file
+fchown-0 ${SB_UID} ${SB_GID} file || exit 1
diff --git a/tests/fchown.at b/tests/fchown.at
new file mode 100644
index 0000000..d364b4b
--- /dev/null
+++ b/tests/fchown.at
@@ -0,0 +1,2 @@
+SB_CHECK(1)
+SB_CHECK(2)
diff --git a/tests/fork-follow_static_tst.c b/tests/fork-follow_static_tst.c
new file mode 100644
index 0000000..363384e
--- /dev/null
+++ b/tests/fork-follow_static_tst.c
@@ -0,0 +1 @@
+#include "fork-follow_tst.c"
diff --git a/tests/fork-follow_tst.c b/tests/fork-follow_tst.c
new file mode 100644
index 0000000..2e3bb95
--- /dev/null
+++ b/tests/fork-follow_tst.c
@@ -0,0 +1,34 @@
+/*
+ * Make sure violations in children are caught.
+ */
+
+#include "tests.h"
+
+int main(int argc, char *argv[])
+{
+ if (argc != 3) {
+ printf("usage: %s <number forks> <path to remove>\n", argv[0]);
+ exit(1);
+ }
+
+ int i, forks = atoi(argv[1]);
+ const char *path = argv[2];
+
+ for (i = 0; i < forks; ++i) {
+ pid_t pid = fork();
+ if (pid < 0)
+ errp("unable to fork");
+
+ if (pid > 0) {
+ /* parent -- wait for child */
+ int status;
+ if (waitpid(pid, &status, 0) == pid)
+ exit(WEXITSTATUS(status));
+ errp("waitpid failed");
+ }
+ /* child -- keep looping */
+ }
+
+ /* final child -- try to create the path */
+ exit(creat(path, 0666) < 0 ? 0 : 1);
+}
diff --git a/tests/get-group.c b/tests/get-group.c
index 8138967..30cdfc9 100644
--- a/tests/get-group.c
+++ b/tests/get-group.c
@@ -31,8 +31,8 @@ int main(int argc, char *argv[])
printf("%i\n", grp->gr_gid);
} else {
const char *file = argv[1];
- struct stat st;
- if (lstat(file, &st))
+ struct stat64 st;
+ if (lstat64(file, &st))
errp("lstat(%s) failed", file);
printf("%i\n", st.st_gid);
}
diff --git a/tests/get-user.c b/tests/get-user.c
index f85e299..be448d7 100644
--- a/tests/get-user.c
+++ b/tests/get-user.c
@@ -31,8 +31,8 @@ int main(int argc, char *argv[])
printf("%i\n", pwd->pw_uid);
} else {
const char *file = argv[1];
- struct stat st;
- if (lstat(file, &st))
+ struct stat64 st;
+ if (lstat64(file, &st))
errp("lstat(%s) failed", file);
printf("%i\n", st.st_uid);
}
diff --git a/tests/git-bisector.sh b/tests/git-bisector.sh
index c45db6e..b64dff6 100755
--- a/tests/git-bisector.sh
+++ b/tests/git-bisector.sh
@@ -21,10 +21,21 @@ make="make -s -j"
cat << EOF > git-run.sh
#!/bin/sh
./autogen.sh
-./configure -q -C $(sandbox -V | tail -n1)
+# Newer versions of sandbox can run configure for us.
+# Should drop old support around Jan 2023.
+if sandbox --help | grep -q -e--run-configure ; then
+ sandbox --run-configure -q -C
+else
+ ./configure -q -C $(sandbox -V | tail -n1)
+fi
${make} clean
${make}
-./src/sandbox.sh . ./data/sandbox.bashrc \; . ./git-run-sandbox.sh
+opt=
+# Older versions of sandbox implied -c all the time.
+if ./src/sandbox.sh --help | grep -q -e--bash ; then
+ opt="-c"
+fi
+./src/sandbox.sh ${opt} . ./data/sandbox.bashrc \; . ./git-run-sandbox.sh
EOF
chmod a+rx git-run.sh
diff --git a/tests/libsigsegv_tst.c b/tests/libsigsegv_tst.c
index 82ed21b..2b17fa4 100644
--- a/tests/libsigsegv_tst.c
+++ b/tests/libsigsegv_tst.c
@@ -11,7 +11,7 @@
#define WRITE(msg) ({ ssize_t w = write(1, msg, sizeof(msg) - 1); w; })
-#ifdef HAVE_SIGSEGV_H
+#if defined(HAVE_SIGSEGV_H) && defined(HAVE_LIBSIGSEGV)
#include <sigsegv.h>
static int segv_handler(void *address, int serious)
diff --git a/tests/local.at b/tests/local.at
index 95db774..028961d 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -6,7 +6,7 @@ dnl due to the default PM test env having that predict.
m4_defun([SB_RUN],[\
env \
SANDBOX_LOG="$PWD/sandbox.log" \
- sandbox.sh \
+ sandbox.sh -c \
addpredict / \; \
addwrite "${PWD%/*}" \; \
set -x \; \
diff --git a/tests/local.mk b/tests/local.mk
new file mode 100644
index 0000000..f1f4ac0
--- /dev/null
+++ b/tests/local.mk
@@ -0,0 +1,150 @@
+AT_FILES = $(wildcard $(top_srcdir)/%D%/*.at)
+DISTCLEANFILES += %D%/atconfig
+
+# Use top_srcdir for dependencies, and abs_top_srcdir to execute it.
+TESTSUITE = $(top_srcdir)/%D%/testsuite
+ABS_TESTSUITE = $(abs_top_srcdir)/%D%/testsuite
+
+EXTRA_DIST += \
+ $(AT_FILES) \
+ $(TESTSUITE) \
+ $(TESTSUITE_LIST) \
+ %D%/atlocal.in \
+ %D%/package.m4.in \
+ %D%/test-skel-0.c \
+ %D%/tests.h \
+ %D%/xattr-0
+
+check_PROGRAMS += \
+ %D%/get-group \
+ %D%/get-user \
+ %D%/sb_true \
+ %D%/sb_true_static \
+ \
+ %D%/access-0 \
+ %D%/chmod-0 \
+ %D%/chown-0 \
+ %D%/creat-0 \
+ %D%/creat64-0 \
+ %D%/execv-0 \
+ %D%/execvp-0 \
+ %D%/faccessat-0 \
+ %D%/fchmod-0 \
+ %D%/fchmodat-0 \
+ %D%/fchown-0 \
+ %D%/fchownat-0 \
+ %D%/fopen-0 \
+ %D%/fopen64-0 \
+ %D%/futimesat-0 \
+ %D%/lchown-0 \
+ %D%/link-0 \
+ %D%/linkat-0 \
+ %D%/linkat_static-0 \
+ %D%/lremovexattr-0 \
+ %D%/lsetxattr-0 \
+ %D%/lutimes-0 \
+ %D%/mkdtemp-0 \
+ %D%/mkdir-0 \
+ %D%/mkdir_static-0 \
+ %D%/mkdirat-0 \
+ %D%/mkfifo-0 \
+ %D%/mkfifoat-0 \
+ %D%/mknod-0 \
+ %D%/mknodat-0 \
+ %D%/mkostemp-0 \
+ %D%/mkostemp64-0 \
+ %D%/mkostemps-0 \
+ %D%/mkostemps64-0 \
+ %D%/mkstemp-0 \
+ %D%/mkstemp64-0 \
+ %D%/mkstemps-0 \
+ %D%/mkstemps64-0 \
+ %D%/open-0 \
+ %D%/open_static-0 \
+ %D%/open64-0 \
+ %D%/openat-0 \
+ %D%/openat_static-0 \
+ %D%/openat64-0 \
+ %D%/opendir-0 \
+ %D%/remove-0 \
+ %D%/removexattr-0 \
+ %D%/rename-0 \
+ %D%/renameat-0 \
+ %D%/renameat2-0 \
+ %D%/rmdir-0 \
+ %D%/setxattr-0 \
+ %D%/signal_static-0 \
+ %D%/symlink-0 \
+ %D%/symlinkat-0 \
+ %D%/truncate-0 \
+ %D%/truncate64-0 \
+ %D%/unlink-0 \
+ %D%/unlink_static-0 \
+ %D%/unlinkat-0 \
+ %D%/utime-0 \
+ %D%/utimensat-0 \
+ %D%/utimensat64-0 \
+ %D%/utimensat_static-0 \
+ %D%/utimensat64_static-0 \
+ %D%/utimes-0 \
+ %D%/vfork-0 \
+ \
+ %D%/fork-follow_tst \
+ %D%/fork-follow_static_tst \
+ %D%/getcwd-gnulib_tst \
+ %D%/libsigsegv_tst \
+ %D%/malloc_hooked_tst \
+ %D%/malloc_mmap_tst \
+ %D%/pipe-fork_tst \
+ %D%/pipe-fork_static_tst \
+ %D%/sb_printf_tst \
+ %D%/sigsuspend-zsh_tst \
+ %D%/sigsuspend-zsh_static_tst \
+ %D%/trace-memory_static_tst
+
+dist_check_SCRIPTS += \
+ $(wildcard $(top_srcdir)/%D%/*-[0-9]*.sh) \
+ %D%/malloc-0 \
+ %D%/script-0 \
+ %D%/trace-0
+
+# This will be used by all programs, not just tests/ ...
+AM_LDFLAGS = `expr $@ : .*_static >/dev/null && echo -all-static`
+
+%C%_sb_printf_tst_CFLAGS = -I$(top_srcdir)/libsbutil -I$(top_srcdir)/libsbutil/include
+%C%_sb_printf_tst_LDADD = libsbutil/libsbutil.la
+
+%C%_malloc_hooked_tst_LDFLAGS = $(AM_LDFLAGS) -pthread
+
+%C%_libsigsegv_tst_CPPFLAGS = ${AM_CPPFLAGS}
+if HAVE_LIBSIGSEGV
+%C%_libsigsegv_tst_CPPFLAGS += -DHAVE_LIBSIGSEGV
+%C%_libsigsegv_tst_LDADD = -lsigsegv
+endif
+
+TESTSUITEFLAGS = --jobs=`getconf _NPROCESSORS_ONLN || echo 1`
+
+# Helper target for devs to precompile.
+tests: $(check_PROGRAMS) $(TESTSUITE)
+
+check-local: %D%/atconfig %D%/atlocal $(TESTSUITE)
+ cd %D% && $(SHELL) '$(ABS_TESTSUITE)' AUTOTEST_PATH='src:tests' $(TESTSUITEFLAGS)
+
+installcheck-local: %D%/atconfig %D%/atlocal $(TESTSUITE)
+ cd %D% && $(SHELL) '$(ABS_TESTSUITE)' AUTOTEST_PATH='src:tests:$(bindir)' $(TESTSUITEFLAGS)
+
+clean-local:
+ test ! -f '$(TESTSUITE)' || { cd %D% && $(SHELL) '$(ABS_TESTSUITE)' --clean; }
+
+TESTSUITE_LIST = $(top_srcdir)/%D%/testsuite.list.at
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): $(AT_FILES) $(TESTSUITE_LIST)
+ @$(MKDIR_P) $(top_srcdir)/%D%
+ $(AM_V_GEN)cd $(top_srcdir)/%D% && $(AUTOTEST) -I. -o testsuite.tmp testsuite.at
+ $(AM_V_at)mv $@.tmp $@
+
+$(TESTSUITE_LIST): $(AT_FILES)
+ @$(MKDIR_P) $(top_srcdir)/%D%
+ $(AM_V_GEN)( echo "dnl DO NOT EDIT: GENERATED BY MAKEFILE.AM"; \
+ $(GREP) -l -e '^SB_CHECK' -e '^AT_CHECK' $(AT_FILES) | LC_ALL=C sort | \
+ $(SED) -e 's:^[^/]*/%D%/:sb_inc([:' -e 's:[.]at$$:]):' ) > $@
diff --git a/tests/lremovexattr-0.c b/tests/lremovexattr-0.c
new file mode 100644
index 0000000..ca925f1
--- /dev/null
+++ b/tests/lremovexattr-0.c
@@ -0,0 +1,15 @@
+#define FUNC lremovexattr
+#define SFUNC "lremovexattr"
+#define FUNC_STR "\"%s\", \"%s\""
+#define FUNC_IMP path, name
+#define ARG_CNT 2
+#define ARG_USE "<path> <name>"
+
+#define process_args() \
+ s = argv[i++]; \
+ char *path = s; \
+ \
+ s = argv[i++]; \
+ char *name = s;
+
+#include "test-skel-0.c"
diff --git a/tests/lsetxattr-0.c b/tests/lsetxattr-0.c
new file mode 100644
index 0000000..b1ed475
--- /dev/null
+++ b/tests/lsetxattr-0.c
@@ -0,0 +1,24 @@
+#define FUNC lsetxattr
+#define SFUNC "lsetxattr"
+#define FUNC_STR "\"%s\", \"%s\", \"%s\", %zu, %i"
+#define FUNC_IMP path, name, value, size, flags
+#define ARG_CNT 5
+#define ARG_USE "<path> <name> <value> <size> <flags>"
+
+#define process_args() \
+ s = argv[i++]; \
+ char *path = s; \
+ \
+ s = argv[i++]; \
+ char *name = s; \
+ \
+ s = argv[i++]; \
+ char *value = s; \
+ \
+ s = argv[i++]; \
+ size_t size = atoi(s); \
+ \
+ s = argv[i++]; \
+ int flags = atoi(s);
+
+#include "test-skel-0.c"
diff --git a/tests/lutimes-1.sh b/tests/lutimes-1.sh
new file mode 100755
index 0000000..8638bb2
--- /dev/null
+++ b/tests/lutimes-1.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+addwrite "${PWD}"
+
+sym="lutimes-1.sym"
+ln -s /bad/path "${sym}"
+
+lutimes-0 0 "${sym}" NULL || exit 1
+lutimes-0 -1,EACCES /bin/sh NULL || exit 1
diff --git a/tests/lutimes.at b/tests/lutimes.at
new file mode 100644
index 0000000..081d7d2
--- /dev/null
+++ b/tests/lutimes.at
@@ -0,0 +1 @@
+SB_CHECK(1)
diff --git a/tests/malloc_hooked_tst.c b/tests/malloc_hooked_tst.c
index 18737fe..8d0922e 100644
--- a/tests/malloc_hooked_tst.c
+++ b/tests/malloc_hooked_tst.c
@@ -9,7 +9,7 @@
* libsandbox tries to initialize itself (since it never finished originally) ->
* libsandbox's malloc() ->
* dlsym() -> deadlock
- * http://crbug.com/586444
+ * https://crbug.com/586444
*/
#include "headers.h"
diff --git a/tests/removexattr-0.c b/tests/removexattr-0.c
new file mode 100644
index 0000000..4abdfff
--- /dev/null
+++ b/tests/removexattr-0.c
@@ -0,0 +1,15 @@
+#define FUNC removexattr
+#define SFUNC "removexattr"
+#define FUNC_STR "\"%s\", \"%s\""
+#define FUNC_IMP path, name
+#define ARG_CNT 2
+#define ARG_USE "<path> <name>"
+
+#define process_args() \
+ s = argv[i++]; \
+ char *path = s; \
+ \
+ s = argv[i++]; \
+ char *name = s;
+
+#include "test-skel-0.c"
diff --git a/tests/removexattr-1.sh b/tests/removexattr-1.sh
new file mode 100755
index 0000000..327f4dd
--- /dev/null
+++ b/tests/removexattr-1.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Make sure we catch removexattr.
+[ "${at_xfail}" = "yes" ] && exit 77 # see trace-0
+xattr-0 ; ret=$? ; [ ${ret} -eq 0 ] || exit ${ret}
+
+# Set it to something to make sure it works.
+touch f
+setxattr-0 0 f user.sandbox test 4 0 || exit 1
+
+# Try to remove it and get rejected.
+adddeny "${PWD}"
+removexattr-0 0 f user.sandbox
+test -e sandbox.log
diff --git a/tests/removexattr.at b/tests/removexattr.at
new file mode 100644
index 0000000..081d7d2
--- /dev/null
+++ b/tests/removexattr.at
@@ -0,0 +1 @@
+SB_CHECK(1)
diff --git a/tests/renameat2-0.c b/tests/renameat2-0.c
new file mode 100644
index 0000000..6041d69
--- /dev/null
+++ b/tests/renameat2-0.c
@@ -0,0 +1,22 @@
+#define CONFIG HAVE_RENAMEAT2
+#define FUNC renameat2
+#define SFUNC "renameat2"
+#define FUNC_STR "%i, \"%s\", %i, \"%s\", %i"
+#define FUNC_IMP olddirfd, oldpath, newdirfd, newpath, 0
+#define ARG_CNT 4
+#define ARG_USE "<dirfd>(old) <path>(old) <dirfd>(new) <path>(new)"
+
+#define process_args() \
+ s = argv[i++]; \
+ int olddirfd = at_get_fd(s); \
+ \
+ s = argv[i++]; \
+ char *oldpath = s; \
+ \
+ s = argv[i++]; \
+ int newdirfd = at_get_fd(s); \
+ \
+ s = argv[i++]; \
+ char *newpath = s;
+
+#include "test-skel-0.c"
diff --git a/tests/renameat2-1.sh b/tests/renameat2-1.sh
new file mode 100755
index 0000000..9f91c05
--- /dev/null
+++ b/tests/renameat2-1.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+# basic functionality check
+
+addwrite $PWD
+
+touch old || exit 1
+renameat2-0 0 AT_FDCWD old AT_FDCWD new || exit 1
+[ ! -e old -a -e new ]
diff --git a/tests/renameat2-2.sh b/tests/renameat2-2.sh
new file mode 100755
index 0000000..420b36d
--- /dev/null
+++ b/tests/renameat2-2.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# make sure we can clobber symlinks #612202
+
+addwrite $PWD
+
+ln -s /asdf sym || exit 1
+touch file
+renameat2-0 0 AT_FDCWD file AT_FDCWD sym || exit 1
+[ ! -e file ]
+[ ! -L sym ]
+[ -e sym ]
+test ! -s "${SANDBOX_LOG}"
diff --git a/tests/renameat2-3.sh b/tests/renameat2-3.sh
new file mode 100755
index 0000000..ca945a5
--- /dev/null
+++ b/tests/renameat2-3.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+# make sure we reject bad renames #612202
+
+addwrite $PWD
+mkdir deny
+adddeny $PWD/deny
+
+touch file
+renameat2-0 -1,EACCES AT_FDCWD file AT_FDCWD deny/file || exit 1
+[ -e file ]
+test -s "${SANDBOX_LOG}"
diff --git a/tests/renameat2.at b/tests/renameat2.at
new file mode 100644
index 0000000..eec4638
--- /dev/null
+++ b/tests/renameat2.at
@@ -0,0 +1,3 @@
+SB_CHECK(1)
+SB_CHECK(2)
+SB_CHECK(3)
diff --git a/tests/script-1.sh b/tests/script-1.sh
index 3ac6252..8eb46bf 100755
--- a/tests/script-1.sh
+++ b/tests/script-1.sh
@@ -1,5 +1,8 @@
#!/bin/sh
-# http://bugs.gentoo.org/257418
+# https://bugs.gentoo.org/257418
[ "${at_xfail}" = "yes" ] && exit 77 # see script-0
-(>/dev/fd/3)
+(
+cd "${devfd}"
+>3
+)
exit 0
diff --git a/tests/script-14.sh b/tests/script-14.sh
index 6fa55a0..6fa55a0 100644..100755
--- a/tests/script-14.sh
+++ b/tests/script-14.sh
diff --git a/tests/script-15.sh b/tests/script-15.sh
index b2acddc..b2acddc 100644..100755
--- a/tests/script-15.sh
+++ b/tests/script-15.sh
diff --git a/tests/script-16.sh b/tests/script-16.sh
index 1622694..73b7803 100755
--- a/tests/script-16.sh
+++ b/tests/script-16.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# http://bugs.gentoo.org/139591
+# https://bugs.gentoo.org/139591
[ "${at_xfail}" = "yes" ] && exit 77 # see script-0
addwrite $PWD
diff --git a/tests/script-17.sh b/tests/script-17.sh
new file mode 100755
index 0000000..83c51f9
--- /dev/null
+++ b/tests/script-17.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Make sure forked children are caught. Historically, dynamic worked fine, but
+# static missed forks.
+[ "${at_xfail}" = "yes" ] && exit 77 # see script-0
+
+# Setup scratch path.
+mkdir subdir
+adddeny "${PWD}/subdir"
+
+for child in 0 1 2 3 4 5 ; do
+ fork-follow_tst ${child} subdir/dyn${child} || exit $?
+done
+
+depth="0"
+# We can't trace static children currently with YAMA ptrace_scope 1+.
+if [ ${at_yama_ptrace_scope} -eq 0 ] ; then
+ depth="${depth} 1 2 3 4 5"
+fi
+for child in ${depth} ; do
+ fork-follow_static_tst ${child} subdir/static${child} || exit $?
+done
+
+exit 0
diff --git a/tests/script-2.sh b/tests/script-2.sh
index ec10fa9..3c7d66e 100755
--- a/tests/script-2.sh
+++ b/tests/script-2.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# http://bugs.gentoo.org/139591
+# https://bugs.gentoo.org/139591
[ "${at_xfail}" = "yes" ] && exit 77 # see script-0
addwrite $PWD
diff --git a/tests/script-3.sh b/tests/script-3.sh
index be7f7a3..60ca5ce 100755
--- a/tests/script-3.sh
+++ b/tests/script-3.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# http://bugs.gentoo.org/260765
+# https://bugs.gentoo.org/260765
[ "${at_xfail}" = "yes" ] && exit 77 # see script-0
addwrite $PWD
diff --git a/tests/script-8.sh b/tests/script-8.sh
index 6d9de55..9d8ca11 100755
--- a/tests/script-8.sh
+++ b/tests/script-8.sh
@@ -6,6 +6,9 @@ sigsuspend-zsh_tst
d=$?
echo "ret = $d"
+# We can't trace static children currently with YAMA ptrace_scope 1+.
+[ ${at_yama_ptrace_scope} -gt 0 ] && exit ${d}
+
sigsuspend-zsh_static_tst
s=$?
echo "ret = $s"
diff --git a/tests/script.at b/tests/script.at
index f1119ef..037d27e 100644
--- a/tests/script.at
+++ b/tests/script.at
@@ -13,4 +13,5 @@ SB_CHECK(12)
SB_CHECK(13)
SB_CHECK(14)
SB_CHECK(15)
-SB_CHECK(16) \ No newline at end of file
+SB_CHECK(16)
+SB_CHECK(17)
diff --git a/tests/setxattr-0.c b/tests/setxattr-0.c
new file mode 100644
index 0000000..2717b85
--- /dev/null
+++ b/tests/setxattr-0.c
@@ -0,0 +1,24 @@
+#define FUNC setxattr
+#define SFUNC "setxattr"
+#define FUNC_STR "\"%s\", \"%s\", \"%s\", %zu, %i"
+#define FUNC_IMP path, name, value, size, flags
+#define ARG_CNT 5
+#define ARG_USE "<path> <name> <value> <size> <flags>"
+
+#define process_args() \
+ s = argv[i++]; \
+ char *path = s; \
+ \
+ s = argv[i++]; \
+ char *name = s; \
+ \
+ s = argv[i++]; \
+ char *value = s; \
+ \
+ s = argv[i++]; \
+ size_t size = atoi(s); \
+ \
+ s = argv[i++]; \
+ int flags = atoi(s);
+
+#include "test-skel-0.c"
diff --git a/tests/setxattr-1.sh b/tests/setxattr-1.sh
new file mode 100755
index 0000000..6bbe1df
--- /dev/null
+++ b/tests/setxattr-1.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Make sure we catch setxattr.
+[ "${at_xfail}" = "yes" ] && exit 77 # see trace-0
+xattr-0 ; ret=$? ; [ ${ret} -eq 0 ] || exit ${ret}
+
+# Set it to something to make sure it works.
+touch f
+setxattr-0 0 f user.sandbox test 4 0 || exit 1
+
+# Try to set it again and get rejected.
+adddeny "${PWD}"
+setxattr-0 0 f user.sandbox test 4 0
+test -e sandbox.log
diff --git a/tests/setxattr.at b/tests/setxattr.at
new file mode 100644
index 0000000..081d7d2
--- /dev/null
+++ b/tests/setxattr.at
@@ -0,0 +1 @@
+SB_CHECK(1)
diff --git a/tests/test-skel-0.c b/tests/test-skel-0.c
index 96e42ae..91128d3 100644
--- a/tests/test-skel-0.c
+++ b/tests/test-skel-0.c
@@ -128,7 +128,7 @@ int at_get_fd(const char *str_dirfd)
}
str_mode = strtok(NULL, ":");
- return open(str_path, f_get_flags(str_flags), sscanf_mode_t(str_mode));
+ return open64(str_path, f_get_flags(str_flags), sscanf_mode_t(str_mode));
}
#define V_TIMESPEC "NULL | NOW | #[,#]"
@@ -144,8 +144,8 @@ struct timespec *parse_timespec(const char *s)
if (!strcmp(s, "NOW")) {
times->tv_sec = time(0);
} else {
- long sec = 0, nsec = 0;
- sscanf(s, "%li,%li", &sec, &nsec);
+ int64_t sec = 0, nsec = 0;
+ sscanf(s, "%" PRIi64 ",%" PRIi64, &sec, &nsec);
times->tv_sec = sec;
times->tv_nsec = nsec;
}
diff --git a/tests/tests.h b/tests/tests.h
index 22733ca..610388d 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -73,6 +73,7 @@ const value_pair tbl_errno[] = {
PAIR(EMLINK)
PAIR(ENAMETOOLONG)
PAIR(ENOBUFS)
+ PAIR(ENODATA)
PAIR(ENODEV)
PAIR(ENOENT)
PAIR(ENOEXEC)
diff --git a/tests/trace-0 b/tests/trace-0
index 5a91c7a..99f3037 100755
--- a/tests/trace-0
+++ b/tests/trace-0
@@ -1,6 +1,6 @@
#!/bin/sh
# make sure trace support exists
-if grep -q trace_child_signal "$abs_top_builddir"/libsandbox/.libs/libsandbox.so ; then
+if grep -q trace_loop "$abs_top_builddir"/libsandbox/.libs/libsandbox.so ; then
# see comment at top of script-0 -- same issue applies here because
# the ld.so isn't around to load the correct sandbox lib for us
exec script-0
diff --git a/tests/trace-memory_static_tst.c b/tests/trace-memory_static_tst.c
index 14c6477..86a47fe 100644
--- a/tests/trace-memory_static_tst.c
+++ b/tests/trace-memory_static_tst.c
@@ -26,7 +26,7 @@ volatile uintptr_t offset = 0;
#define check_ptr(addr) \
({ \
printf(" open(%p)\n", addr); \
- ret = open(non_const_ptr(addr), O_RDONLY); \
+ ret = open64(non_const_ptr(addr), O_RDONLY); \
assert(ret == -1 && errno == EFAULT); \
})
@@ -53,7 +53,7 @@ int main(int argc, char *argv[])
printf(" open(%p -> %p [+%#zx])\n", p, p + len, len);
memset(p, 'a', len);
path[end] = '\0';
- ret = open(p, O_RDONLY);
+ ret = open64(p, O_RDONLY);
assert(ret == -1 && (errno == ENOENT || errno == ENAMETOOLONG));
}
}
diff --git a/tests/utimensat64-0.c b/tests/utimensat64-0.c
new file mode 100644
index 0000000..bbacef5
--- /dev/null
+++ b/tests/utimensat64-0.c
@@ -0,0 +1,3 @@
+#define _TIME_BITS 64
+#define _FILE_OFFSET_BITS 64
+#include "utimensat-0.c"
diff --git a/tests/utimensat64-1.sh b/tests/utimensat64-1.sh
new file mode 100755
index 0000000..2aebc5f
--- /dev/null
+++ b/tests/utimensat64-1.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# basic functionality check
+
+addwrite $PWD
+
+touch -r / file || exit 1
+utimensat64-0 0 AT_FDCWD . NULL 0 || exit 1
+utimensat64-0 0 AT_FDCWD file NULL 0 || exit 1
+[ file -nt / ]
diff --git a/tests/utimensat64.at b/tests/utimensat64.at
new file mode 100644
index 0000000..081d7d2
--- /dev/null
+++ b/tests/utimensat64.at
@@ -0,0 +1 @@
+SB_CHECK(1)
diff --git a/tests/utimensat64_static-0.c b/tests/utimensat64_static-0.c
new file mode 100644
index 0000000..73e7602
--- /dev/null
+++ b/tests/utimensat64_static-0.c
@@ -0,0 +1 @@
+#include "utimensat64-0.c"
diff --git a/tests/utimensat64_static-1.sh b/tests/utimensat64_static-1.sh
new file mode 100755
index 0000000..7b0355c
--- /dev/null
+++ b/tests/utimensat64_static-1.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# basic functionality check
+[ "${at_xfail}" = "yes" ] && exit 77 # see trace-0
+
+addwrite $PWD
+
+touch -r / file || exit 1
+utimensat64_static-0 0 AT_FDCWD . NULL 0 || exit 1
+utimensat64_static-0 0 AT_FDCWD file NULL 0 || exit 1
+[ file -nt / ]
diff --git a/tests/utimensat64_static.at b/tests/utimensat64_static.at
new file mode 100644
index 0000000..081d7d2
--- /dev/null
+++ b/tests/utimensat64_static.at
@@ -0,0 +1 @@
+SB_CHECK(1)
diff --git a/tests/xattr-0 b/tests/xattr-0
new file mode 100755
index 0000000..5504443
--- /dev/null
+++ b/tests/xattr-0
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Make sure the filesystem supports xattrs.
+file=".test.xattrs"
+touch "${file}"
+setxattr-0 0 "${file}" user.sandbox test 4 0 && ret=0 || ret=77
+rm -f "${file}"
+exit "${ret}"