From e72d086a8f4231a4ed6c49a9dc5fc97b4c807f5e Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 23 Nov 2011 17:51:18 +0100 Subject: [PATCH] Disallow / in filenames in ramfs. --- sortix/fs/ramfs.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sortix/fs/ramfs.cpp b/sortix/fs/ramfs.cpp index b3e36401..f29ab6bc 100644 --- a/sortix/fs/ramfs.cpp +++ b/sortix/fs/ramfs.cpp @@ -250,6 +250,14 @@ namespace Sortix return NULL; } + if ( *path++ != '/' ) { Error::Set(ENOENT); return NULL; } + + size_t pathlen = String::Length(path); + for ( size_t i = 0; i < pathlen; i++ ) + { + if ( path[i] == '/' ) { Error::Set(ENOENT); return NULL; } + } + DevBuffer* file = OpenFile(path, flags, mode); if ( !file ) { return NULL; } Device* wrapper = new DevFileWrapper(file, flags); @@ -259,8 +267,6 @@ namespace Sortix DevBuffer* DevRAMFS::OpenFile(const char* path, int flags, mode_t mode) { - if ( *path++ != '/' ) { Error::Set(ENOENT); return NULL; } - // Hack to prevent / from being a filename. if ( path == 0 ) { Error::Set(ENOENT); return NULL; } @@ -314,6 +320,7 @@ namespace Sortix return false; } + if ( !files ) { Error::Set(ENOENT); return false; } size_t index = files->Search(LookupFile, path); if ( index == SIZE_MAX ) { Error::Set(ENOENT); return false; }