From 57e76a65a4a8ef6652e5041f10d414ae12e70b90 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 12 Sep 2024 23:54:58 +0300 Subject: [PATCH] Kernel: Null terminate ext2 directory entries This fixes a weird bug with `ls /bin` --- kernel/kernel/FS/Ext2/Inode.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/FS/Ext2/Inode.cpp b/kernel/kernel/FS/Ext2/Inode.cpp index 21250f7435..efd6d5436f 100644 --- a/kernel/kernel/FS/Ext2/Inode.cpp +++ b/kernel/kernel/FS/Ext2/Inode.cpp @@ -343,7 +343,9 @@ done: { dirp->d_ino = entry.inode; dirp->d_type = entry.file_type; - strncpy(dirp->d_name, entry.name, entry.name_len); + const size_t name_len = BAN::Math::min(entry.name_len, sizeof(dirp->d_name) - 1); + strncpy(dirp->d_name, entry.name, name_len); + dirp->d_name[name_len] = '\0'; dirp++; } entry_span = entry_span.slice(entry.rec_len);