Disallow / in filenames in ramfs.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-11-23 17:51:18 +01:00
parent 2b032b0414
commit e72d086a8f
1 changed files with 9 additions and 2 deletions

View File

@ -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; }