From 2226682e24a5914e98757f5e39f6f76ca9833512 Mon Sep 17 00:00:00 2001 From: Daan Vanoverloop Date: Tue, 3 Oct 2023 11:31:20 +0000 Subject: [PATCH] Fix bug where long directory names might not be null-terminated --- kernel/fs.c | 2 +- mkfs/mkfs.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/fs.c b/kernel/fs.c index c6bab157e3..7a022bb01c 100644 --- a/kernel/fs.c +++ b/kernel/fs.c @@ -597,7 +597,7 @@ dirlink(struct inode *dp, char *name, uint inum) break; } - strncpy(de.name, name, DIRSIZ); + safestrcpy(de.name, name, DIRSIZ); de.inum = inum; if(writei(dp, 0, (uint64)&de, off, sizeof(de)) != sizeof(de)) return -1; diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c index 1ec326bade..2da3de3566 100644 --- a/mkfs/mkfs.c +++ b/mkfs/mkfs.c @@ -151,7 +151,8 @@ main(int argc, char *argv[]) bzero(&de, sizeof(de)); de.inum = xshort(inum); - strncpy(de.name, shortname, DIRSIZ); + strncpy(de.name, shortname, DIRSIZ - 1); + de.name[DIRSIZ - 1] = '\0'; iappend(rootino, &de, sizeof(de)); while((cc = read(fd, buf, sizeof(buf))) > 0)