aboutsummaryrefslogtreecommitdiffstats
path: root/ports/linux/guts/openat.c
diff options
context:
space:
mode:
authorSeebs <seebs@seebs.net>2019-08-02 12:29:04 -0500
committerSeebs <seebs@seebs.net>2019-08-02 12:29:04 -0500
commit060058bb29f70b244e685b3c704eb0641b736f73 (patch)
tree76f5761ad3729960e6d89b493fd39eb8c7e6649a /ports/linux/guts/openat.c
parent097ca3e245200c4a4333964af59a106c42ff3bca (diff)
downloadpseudo-master.zip
pseudo-master.tar.gz
pseudo-master.tar.bz2
use *correct* flags for open/openat, also apply them for related statHEADross/mastermaster
When statting a file that we may or may not be opening with O_NOFOLLOW, we should use lstat (or AT_SYMLINK_NOFOLLOW) to try to get information about the right file. Also when we want to check whether a bit is set, we should use & rather than |. I am an experienced programmer and know the difference between those.
Diffstat (limited to 'ports/linux/guts/openat.c')
-rw-r--r--ports/linux/guts/openat.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/ports/linux/guts/openat.c b/ports/linux/guts/openat.c
index 673ea6e..656ac2b 100644
--- a/ports/linux/guts/openat.c
+++ b/ports/linux/guts/openat.c
@@ -55,9 +55,13 @@
if (flags & O_CREAT) {
save_errno = errno;
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
- rc = real___xstat64(_STAT_VER, path, &buf);
+ if (flags & O_NOFOLLOW) {
+ rc = real___lxstat64(_STAT_VER, path, &buf);
+ } else {
+ rc = real___xstat64(_STAT_VER, path, &buf);
+ }
#else
- rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, 0);
+ rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
#endif
existed = (rc != -1);
if (!existed)
@@ -72,9 +76,13 @@
if (!(flags & O_NONBLOCK) && ((flags & (O_WRONLY | O_RDONLY | O_RDWR)) != O_RDWR)) {
save_errno = errno;
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
- rc = real___xstat64(_STAT_VER, path, &buf);
+ if (flags & O_NOFOLLOW) {
+ rc = real___lxstat64(_STAT_VER, path, &buf);
+ } else {
+ rc = real___xstat64(_STAT_VER, path, &buf);
+ }
#else
- rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, 0);
+ rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
#endif
if (rc != -1 && S_ISFIFO(buf.st_mode)) {
overly_magic_nonblocking = 1;
@@ -126,11 +134,17 @@
}
#endif
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
- stat_rc = real___xstat64(_STAT_VER, path, &buf);
+ if (flags & O_NOFOLLOW) {
+ stat_rc = real___lxstat64(_STAT_VER, path, &buf);
+ } else {
+ stat_rc = real___xstat64(_STAT_VER, path, &buf);
+ }
#else
- stat_rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, 0);
+ stat_rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
#endif
+ pseudo_debug(PDBGF_FILE, "openat(path %s), flags %o, stat rc %d, stat mode %o\n",
+ path, flags, stat_rc, buf.st_mode);
if (stat_rc != -1) {
buf.st_mode = PSEUDO_DB_MODE(buf.st_mode, mode);
if (!existed) {