diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 20b1d307ff..9132fc181e 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -767,6 +767,9 @@ KResult Ext2FSInode::add_child(InodeIdentifier child_id, const StringView& name, LOCKER(m_lock); ASSERT(is_directory()); + if (name.length() > EXT2_NAME_LEN) + return KResult(-ENAMETOOLONG); + #ifdef EXT2_DEBUG dbg() << "Ext2FSInode::add_child(): Adding inode " << child_id.index() << " with name '" << name << " and mode " << mode << " to directory " << index(); #endif diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp index c0c612c9c9..bae0038a52 100644 --- a/Kernel/FileSystem/FileSystem.cpp +++ b/Kernel/FileSystem/FileSystem.cpp @@ -41,6 +41,7 @@ FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, u8 ft) , inode(i) , file_type(ft) { + ASSERT(name_length < (int)sizeof(name)); memcpy(name, n, name_length); name[name_length] = '\0'; } @@ -50,6 +51,7 @@ FS::DirectoryEntry::DirectoryEntry(const char* n, int nl, InodeIdentifier i, u8 , inode(i) , file_type(ft) { + ASSERT(name_length < (int)sizeof(name)); memcpy(name, n, nl); name[nl] = '\0'; } diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h index 31f7f51a73..fa43ba58bc 100644 --- a/Kernel/FileSystem/FileSystem.h +++ b/Kernel/FileSystem/FileSystem.h @@ -47,6 +47,7 @@ public: virtual KResult prepare_to_unmount() const { return KSuccess; } + // FIXME: This data structure is very clunky and unpleasant. Replace it with something nicer. struct DirectoryEntry { DirectoryEntry(const char* name, InodeIdentifier, u8 file_type); DirectoryEntry(const char* name, int name_length, InodeIdentifier, u8 file_type);