mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-01 00:38:48 +00:00
VirtualFileSystem: Check for '.' '..' and empty filenames
This commit adds a check, to prevent empty dot or dot-dot filenames when renaming a file and returns EINVAL in that case.
This commit is contained in:
parent
fe7bacc2df
commit
222b97488a
Notes:
sideshowbarker
2024-07-18 08:44:20 +09:00
Author: https://github.com/ls-1801
Commit: 222b97488a
Pull-request: https://github.com/SerenityOS/serenity/pull/8619
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/MaxWipfli
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/gunnarbeutner
Reviewed-by: https://github.com/sin-ack
1 changed files with 7 additions and 1 deletions
|
@ -525,7 +525,13 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
|
|||
if (old_parent_custody->is_readonly() || new_parent_custody->is_readonly())
|
||||
return EROFS;
|
||||
|
||||
auto old_basename = KLexicalPath::basename(old_path);
|
||||
if (old_basename.is_empty() || old_basename == "."sv || old_basename == ".."sv)
|
||||
return EINVAL;
|
||||
|
||||
auto new_basename = KLexicalPath::basename(new_path);
|
||||
if (new_basename.is_empty() || new_basename == "."sv || new_basename == ".."sv)
|
||||
return EINVAL;
|
||||
|
||||
if (!new_custody_or_error.is_error()) {
|
||||
auto& new_custody = *new_custody_or_error.value();
|
||||
|
@ -546,7 +552,7 @@ KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Cust
|
|||
if (auto result = new_parent_inode.add_child(old_inode, new_basename, old_inode.mode()); result.is_error())
|
||||
return result;
|
||||
|
||||
if (auto result = old_parent_inode.remove_child(KLexicalPath::basename(old_path)); result.is_error())
|
||||
if (auto result = old_parent_inode.remove_child(old_basename); result.is_error())
|
||||
return result;
|
||||
|
||||
return KSuccess;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue