ramfs: Prevent creating files or directories named "." and "..".

Fixes #18031.
This commit is contained in:
Augustin Cavalier 2022-11-29 19:08:16 -05:00
parent 05fdda96b7
commit d48f4fd05f

View File

@ -794,6 +794,9 @@ ramfs_create(fs_volume* _volume, fs_vnode* _dir, const char *name, int openMode,
// check directory
} else if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
// check special names
} else if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
SET_ERROR(error, B_FILE_EXISTS);
} else if (VolumeWriteLocker locker = volume) {
NodeMTimeUpdater mTimeUpdater(dir);
// directory deleted?
@ -1126,6 +1129,9 @@ ramfs_create_dir(fs_volume* _volume, fs_vnode* _dir, const char *name, int mode)
// check directory
} else if (!dir) {
SET_ERROR(error, B_BAD_VALUE);
// check special names
} else if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
SET_ERROR(error, B_FILE_EXISTS);
} else if (VolumeWriteLocker locker = volume) {
NodeMTimeUpdater mTimeUpdater(dir);
// directory deleted?