diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-09-03 19:11:51 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-03 23:20:23 +0200 |
commit | d7b6cc6421c48185f4dfafb24d2b093b86305860 (patch) | |
tree | 7e5ace9318b73d4efe095c43605cd514db1cccaa /Kernel/FileSystem | |
parent | bad23e3f8cc9c66d818ddb2f7bbe7bddce5c09e2 (diff) | |
download | serenity-d7b6cc6421c48185f4dfafb24d2b093b86305860.zip |
Everywhere: Prevent risky implicit casts of (Nonnull)RefPtr
Our existing implementation did not check the element type of the other
pointer in the constructors and move assignment operators. This meant
that some operations that would require explicit casting on raw pointers
were done implicitly, such as:
- downcasting a base class to a derived class (e.g. `Kernel::Inode` =>
`Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp),
- casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>`
in LibIMAP/Client.cpp)
This, of course, allows gross violations of the type system, and makes
the need to type-check less obvious before downcasting. Luckily, while
adding the `static_ptr_cast`s, only two truly incorrect usages were
found; in the other instances, our casts just needed to be made
explicit.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFSComponent.cpp | 4 | ||||
-rw-r--r-- | Kernel/FileSystem/SysFSComponent.h | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index fb5e51d068..176bfb04f9 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -55,7 +55,7 @@ KResult ProcFS::initialize() auto root_inode = ProcFSComponentRegistry::the().root_directory().to_inode(*this); if (root_inode.is_error()) return root_inode.error(); - m_root_inode = static_cast<NonnullRefPtr<ProcFSDirectoryInode>>(root_inode.release_value()); + m_root_inode = static_ptr_cast<ProcFSDirectoryInode>(root_inode.release_value()); return KSuccess; } diff --git a/Kernel/FileSystem/SysFSComponent.cpp b/Kernel/FileSystem/SysFSComponent.cpp index 7878022111..1b3697e499 100644 --- a/Kernel/FileSystem/SysFSComponent.cpp +++ b/Kernel/FileSystem/SysFSComponent.cpp @@ -61,12 +61,12 @@ SysFSDirectory::SysFSDirectory(StringView name, SysFSDirectory const& parent_dir { } -NonnullRefPtr<Inode> SysFSDirectory::to_inode(SysFS const& sysfs_instance) const +NonnullRefPtr<SysFSInode> SysFSDirectory::to_inode(SysFS const& sysfs_instance) const { return SysFSDirectoryInode::create(sysfs_instance, *this); } -NonnullRefPtr<Inode> SysFSComponent::to_inode(SysFS const& sysfs_instance) const +NonnullRefPtr<SysFSInode> SysFSComponent::to_inode(SysFS const& sysfs_instance) const { return SysFSInode::create(sysfs_instance, *this); } diff --git a/Kernel/FileSystem/SysFSComponent.h b/Kernel/FileSystem/SysFSComponent.h index 3e29138a5f..cefa342650 100644 --- a/Kernel/FileSystem/SysFSComponent.h +++ b/Kernel/FileSystem/SysFSComponent.h @@ -26,7 +26,7 @@ public: virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); }; virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, FileDescription*) { return EROFS; } - virtual NonnullRefPtr<Inode> to_inode(SysFS const&) const; + virtual NonnullRefPtr<SysFSInode> to_inode(SysFS const&) const; InodeIndex component_index() const { return m_component_index; }; @@ -45,7 +45,7 @@ public: virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual RefPtr<SysFSComponent> lookup(StringView name) override; - virtual NonnullRefPtr<Inode> to_inode(SysFS const& sysfs_instance) const override final; + virtual NonnullRefPtr<SysFSInode> to_inode(SysFS const& sysfs_instance) const override final; protected: explicit SysFSDirectory(StringView name); |