mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Kernel: Harden DevFS Vector usage against OOM.
The dance here is not complicated, but it is something that should be taken note of. Since we append to both lists, we don't want to orphan the new Inode in the m_links/m_subfolders Vector in the event that the append to m_parent_fs.m_nodes fails.
This commit is contained in:
parent
a678851b41
commit
ee84b8a845
Notes:
sideshowbarker
2024-07-18 18:50:09 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/ee84b8a8451 Pull-request: https://github.com/SerenityOS/serenity/pull/6756 Reviewed-by: https://github.com/awesomekling
@ -275,6 +275,10 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
|
||||
if (name != "pts")
|
||||
return EROFS;
|
||||
auto new_directory_inode = adopt_ref(*new DevFSPtsDirectoryInode(m_parent_fs));
|
||||
if (!m_subfolders.try_ensure_capacity(m_subfolders.size() + 1))
|
||||
return ENOMEM;
|
||||
if (!m_parent_fs.m_nodes.try_ensure_capacity(m_parent_fs.m_nodes.size() + 1))
|
||||
return ENOMEM;
|
||||
m_subfolders.append(new_directory_inode);
|
||||
m_parent_fs.m_nodes.append(new_directory_inode);
|
||||
return KResult(KSuccess);
|
||||
@ -285,6 +289,10 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
|
||||
return EEXIST;
|
||||
}
|
||||
auto new_link_inode = adopt_ref(*new DevFSLinkInode(m_parent_fs, name));
|
||||
if (!m_links.try_ensure_capacity(m_links.size() + 1))
|
||||
return ENOMEM;
|
||||
if (!m_parent_fs.m_nodes.try_ensure_capacity(m_parent_fs.m_nodes.size() + 1))
|
||||
return ENOMEM;
|
||||
m_links.append(new_link_inode);
|
||||
m_parent_fs.m_nodes.append(new_link_inode);
|
||||
return new_link_inode;
|
||||
|
Loading…
Reference in New Issue
Block a user