mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
Kernel: rmdir("/") should fail instead of asserting
We can't assume there's always a parent custody -- when we open "/" there isn't gonna be one! Fixes #1858.
This commit is contained in:
parent
4c19305a17
commit
7eeea4d57f
2 changed files with 14 additions and 0 deletions
|
@ -630,6 +630,9 @@ KResult VFS::rmdir(StringView path, Custody& base)
|
||||||
if (!inode.is_directory())
|
if (!inode.is_directory())
|
||||||
return KResult(-ENOTDIR);
|
return KResult(-ENOTDIR);
|
||||||
|
|
||||||
|
if (!parent_custody)
|
||||||
|
return KResult(-EBUSY);
|
||||||
|
|
||||||
auto& parent_inode = parent_custody->inode();
|
auto& parent_inode = parent_custody->inode();
|
||||||
|
|
||||||
if (!parent_inode.metadata().may_write(*Process::current))
|
if (!parent_inode.metadata().may_write(*Process::current))
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
|
#include <AK/LogStream.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -293,6 +294,15 @@ void test_writev()
|
||||||
close(pipefds[1]);
|
close(pipefds[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_rmdir_root()
|
||||||
|
{
|
||||||
|
int rc = rmdir("/");
|
||||||
|
if (rc != -1 || errno != EBUSY) {
|
||||||
|
warn() << "rmdir(/) didn't fail with EBUSY";
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -319,6 +329,7 @@ int main(int, char**)
|
||||||
test_eoverflow();
|
test_eoverflow();
|
||||||
test_rmdir_while_inside_dir();
|
test_rmdir_while_inside_dir();
|
||||||
test_writev();
|
test_writev();
|
||||||
|
test_rmdir_root();
|
||||||
|
|
||||||
EXPECT_ERROR_2(EPERM, link, "/", "/home/anon/lolroot");
|
EXPECT_ERROR_2(EPERM, link, "/", "/home/anon/lolroot");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue