From 231f73c4f982987773be5a96370d913e5aaf567c Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 29 Jan 2015 21:06:31 +0100 Subject: [PATCH] Fix extfs symbolic link access and truncation bugs. --- ext/extfs.cpp | 4 ++-- ext/inode.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ext/extfs.cpp b/ext/extfs.cpp index 3eed283b..90e4e243 100644 --- a/ext/extfs.cpp +++ b/ext/extfs.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013, 2014. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2014, 2015. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -600,7 +600,7 @@ void HandleSymlink(int chl, struct fsm_req_symlink* msg, Filesystem* fs) inode->Unref(); return; } - memcpy(dest, dest_raw, msg->namelen); + memcpy(dest, dest_raw, msg->targetlen); dest[msg->targetlen] = '\0'; char* path_raw = (char*) dest_raw + msg->targetlen; diff --git a/ext/inode.cpp b/ext/inode.cpp index d8ec1f3f..93e864ad 100644 --- a/ext/inode.cpp +++ b/ext/inode.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2013. + Copyright(C) Jonas 'Sortie' Termansen 2013, 2014, 2015. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -389,10 +389,15 @@ Inode* Inode::Open(const char* elem, int flags, mode_t mode) block->Unref(); if ( flags & O_EXCL ) return errno = EEXIST, (Inode*) NULL; - if ( flags & O_DIRECTORY && file_type && file_type != EXT2_FT_DIR ) + if ( (flags & O_DIRECTORY) && + file_type != EXT2_FT_UNKNOWN && + file_type != EXT2_FT_DIR && + file_type != EXT2_FT_SYMLINK ) return errno = EEXIST, (Inode*) NULL; Inode* inode = filesystem->GetInode(inode_id); - if ( flags & O_DIRECTORY && !EXT2_S_ISDIR(inode->Mode()) ) + if ( flags & O_DIRECTORY && + !EXT2_S_ISDIR(inode->Mode()) && + !EXT2_S_ISLNK(inode->Mode()) ) { inode->Unref(); return errno = EEXIST, (Inode*) NULL;