1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:37:45 +00:00

Kernel: Make custody_for_dirfd() fail on files other than directories

This commit is contained in:
Andreas Kling 2023-04-03 15:54:14 +02:00
parent 41f5598516
commit f0c9c5e076

View file

@ -1084,11 +1084,12 @@ ErrorOr<NonnullRefPtr<Custody>> Process::custody_for_dirfd(int dirfd)
{ {
if (dirfd == AT_FDCWD) if (dirfd == AT_FDCWD)
return current_directory(); return current_directory();
auto description = TRY(open_file_description(dirfd));
auto base_description = TRY(open_file_description(dirfd)); if (!description->custody())
if (!base_description->custody())
return EINVAL; return EINVAL;
return *base_description->custody(); if (!description->is_directory())
return ENOTDIR;
return *description->custody();
} }
SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> const& Process::name() const SpinlockProtected<NonnullOwnPtr<KString>, LockRank::None> const& Process::name() const