diff options
Diffstat (limited to 'libsandbox/wrapper-funcs/openat_pre_check.c')
-rw-r--r-- | libsandbox/wrapper-funcs/openat_pre_check.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libsandbox/wrapper-funcs/openat_pre_check.c b/libsandbox/wrapper-funcs/openat_pre_check.c new file mode 100644 index 0000000..7f5e823 --- /dev/null +++ b/libsandbox/wrapper-funcs/openat_pre_check.c @@ -0,0 +1,28 @@ +/* + * open*() pre-check. + * + * Copyright 1999-2009 Gentoo Foundation + * Licensed under the GPL-2 + */ + +bool sb_openat_pre_check(const char *func, const char *pathname, int dirfd, int flags) +{ + if (!(flags & O_CREAT)) { + /* If we're not trying to create, fail normally if + * file does not stat + */ + if (dirfd == AT_FDCWD || pathname[0] == '/') { + struct stat st; + save_errno(); + if (-1 == stat(pathname, &st)) { + if (is_env_on(ENV_SANDBOX_DEBUG)) + SB_EINFO("EARLY FAIL", " %s(%s): %s\n", + func, pathname, strerror(errno)); + return false; + } + restore_errno(); + } + } + + return true; +} |