summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/TmpFS.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-01 22:18:59 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-02 18:08:02 +0100
commitdb4388f21b87c99ff5d2b83cb3ea87a88a41e7d0 (patch)
tree4c8a5668fd04053199129ef7e8f55f7633def468 /Kernel/FileSystem/TmpFS.cpp
parent63e8cf8d5943cf32b3123fc7b71521858759d384 (diff)
downloadserenity-db4388f21b87c99ff5d2b83cb3ea87a88a41e7d0.zip
Kernel/TmpFS: Prevent TmpFS::add_child() from adding duplicate children
If asked to add an already existing name to a directory inode, fail with EEXIST, consistent with other filesystems.
Diffstat (limited to 'Kernel/FileSystem/TmpFS.cpp')
-rw-r--r--Kernel/FileSystem/TmpFS.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp
index c42802d77d..93a1fbeb26 100644
--- a/Kernel/FileSystem/TmpFS.cpp
+++ b/Kernel/FileSystem/TmpFS.cpp
@@ -271,13 +271,19 @@ ErrorOr<void> TmpFSInode::add_child(Inode& child, StringView name, mode_t)
if (name.length() > NAME_MAX)
return ENAMETOOLONG;
+ MutexLocker locker(m_inode_lock);
+ for (auto const& existing_child : m_children) {
+ if (existing_child.name->view() == name)
+ return EEXIST;
+ }
+
auto name_kstring = TRY(KString::try_create(name));
// Balanced by `delete` in remove_child()
+
auto* child_entry = new (nothrow) Child { move(name_kstring), static_cast<TmpFSInode&>(child) };
if (!child_entry)
return ENOMEM;
- MutexLocker locker(m_inode_lock);
m_children.append(*child_entry);
did_add_child(child.identifier(), name);
return {};