mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
Kernel+LibC: Don't allow a directory to become a subdirectory of itself
If you try to do this (e.g "mv directory directory"), sys$rename() will now fail with EDIRINTOSELF. Dr. POSIX says we should return EINVAL for this, but a custom error code allows us to print a much more helpful error message when this problem occurs. :^)
This commit is contained in:
parent
13aa3d2d62
commit
a28f29c82c
3 changed files with 8 additions and 1 deletions
|
@ -522,6 +522,11 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
|
||||||
if (&old_parent_inode.fs() != &new_parent_inode.fs())
|
if (&old_parent_inode.fs() != &new_parent_inode.fs())
|
||||||
return KResult(-EXDEV);
|
return KResult(-EXDEV);
|
||||||
|
|
||||||
|
for (auto* new_ancestor = new_parent_custody.ptr(); new_ancestor; new_ancestor = new_ancestor->parent()) {
|
||||||
|
if (&old_inode == &new_ancestor->inode())
|
||||||
|
return KResult(-EDIRINTOSELF);
|
||||||
|
}
|
||||||
|
|
||||||
auto current_process = Process::current();
|
auto current_process = Process::current();
|
||||||
if (!new_parent_inode.metadata().may_write(*current_process))
|
if (!new_parent_inode.metadata().may_write(*current_process))
|
||||||
return KResult(-EACCES);
|
return KResult(-EACCES);
|
||||||
|
|
|
@ -99,4 +99,5 @@
|
||||||
#define EPROTO 71
|
#define EPROTO 71
|
||||||
#define ENOTSUP 72
|
#define ENOTSUP 72
|
||||||
#define EPFNOSUPPORT 73
|
#define EPFNOSUPPORT 73
|
||||||
#define EMAXERRNO 74
|
#define EDIRINTOSELF 74
|
||||||
|
#define EMAXERRNO 75
|
||||||
|
|
|
@ -364,6 +364,7 @@ const char* const sys_errlist[] = {
|
||||||
"Protocol error",
|
"Protocol error",
|
||||||
"Not supported",
|
"Not supported",
|
||||||
"Protocol family not supported",
|
"Protocol family not supported",
|
||||||
|
"Cannot make directory a subdirectory of itself",
|
||||||
"The highest errno +1 :^)",
|
"The highest errno +1 :^)",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue