aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-12-24 19:41:49 -0500
committerMike Frysinger <vapier@gentoo.org>2013-02-24 23:01:53 -0500
commit0b8a6d9773cc0e6d86bf1187f46817d5716698fe (patch)
tree6b89113f5e8b74515f44221ac5b27adbc3386c9e
parentlibsandbox: reject "" paths with *at funcs before checking the dirfd (diff)
downloadsandbox-0b8a6d9773cc0e6d86bf1187f46817d5716698fe.tar.gz
sandbox-0b8a6d9773cc0e6d86bf1187f46817d5716698fe.tar.bz2
sandbox-0b8a6d9773cc0e6d86bf1187f46817d5716698fe.zip
libsandbox: reject "" paths with *at funcs before checking the dirfd [missing file]
When it comes to processing errors, an empty path is checked before an invalid dirfd. Make sure sandbox matches that behavior for the random testsuites out there that look for this. Forgot to `git add` in the previous commit :/. URL: https://bugs.gentoo.org/346929 Reported-by: Marien Zwart <marienz@gentoo.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--libsandbox/wrapper-funcs/__pre_at_check.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libsandbox/wrapper-funcs/__pre_at_check.c b/libsandbox/wrapper-funcs/__pre_at_check.c
new file mode 100644
index 0000000..f72c40c
--- /dev/null
+++ b/libsandbox/wrapper-funcs/__pre_at_check.c
@@ -0,0 +1,34 @@
+/*
+ * common *at() pre-checks.
+ *
+ * Copyright 1999-2012 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+/* We assume the parent has nested use with save/restore errno */
+bool sb_common_at_pre_check(const char *func, const char **pathname, int dirfd,
+ char *dirfd_path, size_t dirfd_path_len)
+{
+ /* the empty path name should fail with ENOENT before any dirfd
+ * checks get a chance to run #346929
+ */
+ if (*pathname && *pathname[0] == '\0') {
+ errno = ENOENT;
+ sb_debug_dyn("EARLY FAIL: %s(%s): %s\n",
+ func, *pathname, strerror(errno));
+ return false;
+ }
+
+ /* Expand the dirfd path first */
+ switch (resolve_dirfd_path(dirfd, *pathname, dirfd_path, dirfd_path_len)) {
+ case -1:
+ sb_debug_dyn("EARLY FAIL: %s(%s) @ resolve_dirfd_path: %s\n",
+ func, *pathname, strerror(errno));
+ return false;
+ case 0:
+ *pathname = dirfd_path;
+ break;
+ }
+
+ return true;
+}