From: Lawrence S. <ljs...@us...> - 2013-04-18 16:00:58
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 4f338fd7a8bcc34f241a39555d09d25db2e9674f (commit) from 5989a9630505b63b3b167b5609b0d30a0c58e532 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4f338fd7a8bcc34f241a39555d09d25db2e9674f Author: Lawrence Sebald <ljs...@us...> Date: Thu Apr 18 12:00:35 2013 -0400 Fix a few error conditions in libkosext2fs. ----------------------------------------------------------------------- Summary of changes: addons/libkosext2fs/fs_ext2.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/libkosext2fs/fs_ext2.c b/addons/libkosext2fs/fs_ext2.c index e936d67..b8305b5 100644 --- a/addons/libkosext2fs/fs_ext2.c +++ b/addons/libkosext2fs/fs_ext2.c @@ -252,12 +252,26 @@ static ssize_t fs_ext2_read(void *h, void *buf, size_t cnt) { mutex_lock(&ext2_mutex); /* Check that the fd is valid */ - if(fd >= MAX_EXT2_FILES || !fh[fd].inode_num || (fh[fd].mode & O_DIR)) { + if(fd >= MAX_EXT2_FILES || !fh[fd].inode_num) { mutex_unlock(&ext2_mutex); errno = EINVAL; return -1; } + /* Make sure we're not trying to read a file not opened for reading. */ + if(!(fh[fd].mode & O_RDONLY)) { + mutex_unlock(&ext2_mutex); + errno = EBADF; + return -1; + } + + /* Make sure we're not trying to read a directory with read */ + if(fh[fd].mode & O_DIR) { + mutex_unlock(&ext2_mutex); + errno = EISDIR; + return -1; + } + /* Do we have enough left? */ if((fh[fd].ptr + cnt) > fh[fd].inode->i_size) cnt = fh[fd].inode->i_size - fh[fd].ptr; @@ -403,7 +417,7 @@ static dirent_t *fs_ext2_readdir(void *h) { /* Check that the fd is valid */ if(fd >= MAX_EXT2_FILES || !fh[fd].inode_num || !(fh[fd].mode & O_DIR)) { mutex_unlock(&ext2_mutex); - errno = EINVAL; + errno = EBADF; return NULL; } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |