Fix linux_newfstatat

"If pathname is absolute, then dirfd is ignored."
This commit is contained in:
EnderIce2 2024-03-31 19:37:56 +03:00
parent f5a6a39159
commit fcccb5b44f
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -2491,7 +2491,7 @@ static int linux_openat(SysFrm *, int dirfd, const char *pathname, int flags, mo
} }
/* Undocumented? */ /* Undocumented? */
static long linux_newfstatat(SysFrm *, int dfd, const char *pathname, static long linux_newfstatat(SysFrm *, int dirfd, const char *pathname,
struct stat *statbuf, int flag) struct stat *statbuf, int flag)
{ {
/* FIXME: This function is not working at all? */ /* FIXME: This function is not working at all? */
@ -2508,7 +2508,9 @@ static long linux_newfstatat(SysFrm *, int dfd, const char *pathname,
if (pPathname == nullptr || pStatbuf == nullptr) if (pPathname == nullptr || pStatbuf == nullptr)
return -EFAULT; return -EFAULT;
if (dfd == AT_FDCWD) debug("%s %#lx %#lx", pPathname, pathname, statbuf);
if (dirfd == AT_FDCWD && !fs->PathIsRelative(pPathname))
{ {
vfs::RefNode *absoluteNode = fs->Open(pPathname, pcb->CurrentWorkingDirectory); vfs::RefNode *absoluteNode = fs->Open(pPathname, pcb->CurrentWorkingDirectory);
if (!absoluteNode) if (!absoluteNode)
@ -2523,14 +2525,13 @@ static long linux_newfstatat(SysFrm *, int dfd, const char *pathname,
} }
vfs::FileDescriptorTable::Fildes & vfs::FileDescriptorTable::Fildes &
fildes = fdt->GetDescriptor(dfd); fildes = fdt->GetDescriptor(dirfd);
if (!fildes.Handle) if (!fildes.Handle)
{ {
debug("Invalid fd %d", dfd); debug("Invalid fd %d", dirfd);
return -EBADF; return -EBADF;
} }
debug("%s %#lx %#lx", pPathname, pathname, statbuf);
return fdt->_stat(pPathname, pStatbuf); return fdt->_stat(pPathname, pStatbuf);
} }