From 3a267efe0b7694ba5a328db6c3f5b1a049406ee1 Mon Sep 17 00:00:00 2001 From: Douglas Thain Date: Mon, 18 Dec 2023 09:45:46 -0500 Subject: [PATCH] Make DISKFS_NAME_MAX a distinct symbol. Check for name length in diskfs_dirent_create_file_or_dir. --- kernel/diskfs.c | 2 ++ kernel/diskfs.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/diskfs.c b/kernel/diskfs.c index 42efb6e5..a0227cad 100644 --- a/kernel/diskfs.c +++ b/kernel/diskfs.c @@ -391,6 +391,8 @@ static int diskfs_dirent_add( struct fs_dirent *d, const char *name, int type, i struct fs_dirent * diskfs_dirent_create_file_or_dir( struct fs_dirent *d, const char *name, int type ) { + if(strlen(name)>DISKFS_NAME_MAX) return 0; // KERROR_NAME_TOO_LONG + struct fs_dirent *t = diskfs_dirent_lookup(d,name); if(t) { diskfs_dirent_close(t); diff --git a/kernel/diskfs.h b/kernel/diskfs.h index ddf85d37..ee63efb3 100644 --- a/kernel/diskfs.h +++ b/kernel/diskfs.h @@ -38,12 +38,15 @@ struct diskfs_inode { #define DISKFS_ITEM_FILE 1 #define DISKFS_ITEM_DIR 2 +/* Maximum name length chosen so that diskfs_item is 32 bytes. */ +#define DISKFS_NAME_MAX 26 + #pragma pack(1) struct diskfs_item { uint32_t inumber; uint8_t type; uint8_t name_length; - char name[26]; + char name[DISKFS_NAME_MAX]; }; #pragma pack()