[gentoo-commits] proj/sandbox:master commit in: libsandbox/, libsbutil/src/, libsandbox/wrapper-funcs/

2021-11-05 Thread Mike Frysinger
commit: 382f70b8d93d012648edc7a42087a6d4d5a103eb
Author: Mike Frysinger  gentoo  org>
AuthorDate: Fri Nov  5 10:23:34 2021 +
Commit: Mike Frysinger  gentoo  org>
CommitDate: Fri Nov  5 10:23:34 2021 +
URL:https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=382f70b8

libsandbox/libsbutil: use faccessat for file-existence tests

This is faster than using stat since it doesn't have to gather all
the metadata, and should avoid LFS issues as a result.

Bug: https://bugs.gentoo.org/583282
Signed-off-by: Mike Frysinger  gentoo.org>

 libsandbox/pre_check_openat.c  | 15 +++
 libsandbox/wrapper-funcs/fopen_pre_check.c |  3 +--
 libsbutil/src/file.c   | 14 +-
 3 files changed, 5 insertions(+), 27 deletions(-)

diff --git a/libsandbox/pre_check_openat.c b/libsandbox/pre_check_openat.c
index 8cf8133..8fd3b23 100644
--- a/libsandbox/pre_check_openat.c
+++ b/libsandbox/pre_check_openat.c
@@ -12,24 +12,15 @@
 
 bool sb_openat_pre_check(const char *func, const char *pathname, int dirfd, 
int flags)
 {
-   /* If we're not trying to create, fail normally if
-* file does not stat
-*/
+   /* If we're not trying to create, fail normally if file does not stat */
if (flags & O_CREAT)
return true;
 
save_errno();
 
-   /* Check incoming args against common *at issues */
-   char dirfd_path[SB_PATH_MAX];
-   if (!sb_common_at_pre_check(func, , dirfd, dirfd_path, 
sizeof(dirfd_path)))
-   return false;
-
/* Doesn't exist -> skip permission checks */
-   struct stat st;
-   if (((flags & O_NOFOLLOW) ? lstat(pathname, ) : stat(pathname, )) 
== -1) {
-   sb_debug_dyn("EARLY FAIL: %s(%s): %s\n",
-   func, pathname, strerror(errno));
+   if (faccessat(dirfd, pathname, F_OK, (flags & O_NOFOLLOW) ? 
AT_SYMLINK_NOFOLLOW : 0) == -1) {
+   sb_debug_dyn("EARLY FAIL: %s(%s): %s\n", func, pathname, 
strerror(errno));
return false;
}
 

diff --git a/libsandbox/wrapper-funcs/fopen_pre_check.c 
b/libsandbox/wrapper-funcs/fopen_pre_check.c
index 765526e..95108e0 100644
--- a/libsandbox/wrapper-funcs/fopen_pre_check.c
+++ b/libsandbox/wrapper-funcs/fopen_pre_check.c
@@ -11,8 +11,7 @@ bool sb_fopen_pre_check(const char *func, const char 
*pathname, const char *mode
save_errno();
 
/* If we're trying to read, fail normally if file does not stat 
*/
-   struct stat st;
-   if (-1 == stat(pathname, )) {
+   if (faccessat(AT_FDCWD, pathname, F_OK, 0) == -1) {
sb_debug_dyn("EARLY FAIL: %s(%s): %s\n",
func, pathname, strerror(errno));
return false;

diff --git a/libsbutil/src/file.c b/libsbutil/src/file.c
index 4542ae5..a1a4a0e 100644
--- a/libsbutil/src/file.c
+++ b/libsbutil/src/file.c
@@ -15,19 +15,7 @@
 bool
 rc_file_exists (const char *pathname)
 {
-  struct stat buf;
-  int retval;
-
-  if (!check_str (pathname))
-return false;
-
-  retval = lstat (pathname, );
-  if (-1 != retval)
-retval = true;
-  else
-retval = false;
-
-  return retval;
+  return faccessat(AT_FDCWD, pathname, F_OK, AT_SYMLINK_NOFOLLOW) == 0;
 }
 
 bool



[gentoo-commits] proj/sandbox:master commit in: libsandbox/, libsbutil/, src/

2021-10-22 Thread Michał Górny
commit: 53ffbaeb24f6ee22a2dcd70fad29c86a4dd863c2
Author: Michał Górny  gentoo  org>
AuthorDate: Fri Oct 22 07:21:35 2021 +
Commit: Michał Górny  gentoo  org>
CommitDate: Fri Oct 22 07:21:35 2021 +
URL:https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=53ffbaeb

Remove leftover generated Makefiles from the repo (sic!)

Signed-off-by: Michał Górny  gentoo.org>

 libsandbox/Makefile | 4 
 libsbutil/Makefile  | 4 
 src/Makefile| 4 
 3 files changed, 12 deletions(-)

diff --git a/libsandbox/Makefile b/libsandbox/Makefile
deleted file mode 100644
index 2db82ff..000
--- a/libsandbox/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-# Helper for developers.
-all libsandbox libsandbox.la: libsandbox/libsandbox.la ;
-clean: ; rm -f *.o *.l[ao] .libs/*
-%: ; $(MAKE) -C .. $@

diff --git a/libsbutil/Makefile b/libsbutil/Makefile
deleted file mode 100644
index f5638c7..000
--- a/libsbutil/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-# Helper for developers.
-all libsbutil libsbutil.la: libsbutil/libsbutil.la ;
-clean: ; rm -f *.o *.l[ao] .libs/*
-%: ; $(MAKE) -C .. $@

diff --git a/src/Makefile b/src/Makefile
deleted file mode 100644
index 4b2bc35..000
--- a/src/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-# Helper for developers.
-all sandbox: src/sandbox ;
-clean: ; rm -f *.o *.l[ao] .libs/* sandbox
-%: ; $(MAKE) -C .. $@