소스 검색

Ext2FS: Trying to create a too-long directory entry should ENAMETOOLONG

Also added some assertions to DirectoryEntry in case someone tries to
instantiate them with names that would overflow the name buffer.

DirectoryEntry is a crappy data structure, and the name buffer is also
crappy. Added a FIXME about replacing it with something nicer.

Before this patch, the DirectoryEntry::name buffer would overflow if
you did "touch extremely-long-file-name". Duh.

Fixes #538.
Andreas Kling 5 년 전
부모
커밋
b9be6b7bb4
3개의 변경된 파일6개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      Kernel/FileSystem/Ext2FileSystem.cpp
  2. 2 0
      Kernel/FileSystem/FileSystem.cpp
  3. 1 0
      Kernel/FileSystem/FileSystem.h

+ 3 - 0
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

+ 2 - 0
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';
 }

+ 1 - 0
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);