From: falcovorbis <fal...@us...> - 2024-05-05 07:29:19
|
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 dce7ef2a8f8c36a4487e1688daa62da847c4ef42 (commit) from dbdc05cf9f64a32b679285c2bb5bb196546407d7 (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 dce7ef2a8f8c36a4487e1688daa62da847c4ef42 Author: Donald Haase <qu...@ya...> Date: Sun May 5 03:28:59 2024 -0400 Fanalyzer ffixes (#544) * Seal memory leak * Zero out initial dir data to prevent uninitialized reads * Prevent memsetting NULL on OOM * Check and report OOM, clean up RO check for random open --------- Co-authored-by: QuzarDC <qu...@co...> ----------------------------------------------------------------------- Summary of changes: addons/libppp/ppp.c | 2 ++ kernel/arch/dreamcast/fs/vmufs.c | 3 +++ kernel/arch/dreamcast/sound/snd_mem.c | 14 ++++++++++++++ kernel/fs/fs_null.c | 4 ++++ kernel/fs/fs_random.c | 18 +++++++++--------- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/addons/libppp/ppp.c b/addons/libppp/ppp.c index abaf354a..d5de66ad 100644 --- a/addons/libppp/ppp.c +++ b/addons/libppp/ppp.c @@ -460,6 +460,8 @@ int ppp_set_login(const char *username, const char *password) { if(password) { if(!(pw = (char *)malloc(strlen(password) + 1))) { + if(username) + free(un); mutex_unlock(&mutex); return -1; } diff --git a/kernel/arch/dreamcast/fs/vmufs.c b/kernel/arch/dreamcast/fs/vmufs.c index bafaafe9..c40fc658 100644 --- a/kernel/arch/dreamcast/fs/vmufs.c +++ b/kernel/arch/dreamcast/fs/vmufs.c @@ -527,6 +527,9 @@ static int vmufs_setup(maple_device_t * dev, vmu_root_t * root, vmu_dir_t ** dir goto dead; } + /* Ensure that the dir is 0'd to avoid possible uninitialized reads */ + memset(*dir, 0, sizeof(*dirsize)); + /* Read it */ if(vmufs_dir_read(dev, root, *dir) < 0) { free(*dir); diff --git a/kernel/arch/dreamcast/sound/snd_mem.c b/kernel/arch/dreamcast/sound/snd_mem.c index c2638154..ee85418b 100644 --- a/kernel/arch/dreamcast/sound/snd_mem.c +++ b/kernel/arch/dreamcast/sound/snd_mem.c @@ -89,6 +89,13 @@ int snd_mem_init(uint32 reserve) { TAILQ_INIT(&pool); blk = (snd_block_t *)malloc(sizeof(snd_block_t)); + + if(!blk) { + spinlock_unlock(&snd_mem_mutex); + errno = ENOMEM; + return -1; + } + memset(blk, 0, sizeof(snd_block_t)); blk->addr = reserve; blk->size = 2 * 1024 * 1024 - reserve; @@ -190,6 +197,13 @@ uint32 snd_mem_malloc(size_t size) { /* Nope: break it up into two chunks */ e = (snd_block_t*)malloc(sizeof(snd_block_t)); + + if(e == NULL) { + dbglog(DBG_ERROR, "snd_mem_malloc: not enough main memory to alloc(%d)\n", size); + spinlock_unlock(&snd_mem_mutex); + return 0; + } + memset(e, 0, sizeof(snd_block_t)); e->addr = best->addr + size; e->size = best->size - size; diff --git a/kernel/fs/fs_null.c b/kernel/fs/fs_null.c index d41f536f..7fbea93e 100644 --- a/kernel/fs/fs_null.c +++ b/kernel/fs/fs_null.c @@ -38,6 +38,10 @@ static null_fh_t *null_open_file(vfs_handler_t *vfs, const char *fn, int mode) { /* Malloc a new fh struct */ fd = malloc(sizeof(null_fh_t)); + if(!fd) { + errno = ENOMEM; + return NULL; + } /* Fill in the filehandle struct */ fd->mode = mode; diff --git a/kernel/fs/fs_random.c b/kernel/fs/fs_random.c index 28749a35..1008c2c3 100644 --- a/kernel/fs/fs_random.c +++ b/kernel/fs/fs_random.c @@ -51,22 +51,22 @@ static rnd_fh_t *rnd_open_file(vfs_handler_t *vfs, const char *fn, int mode) { (void) fn; rnd_fh_t * fd; /* file descriptor */ - int realmode; + + /* We only allow reading, not writing */ + if((mode & O_MODE_MASK) != O_RDONLY) { + errno = EPERM; + return NULL; /* Malloc a new fh struct */ fd = malloc(sizeof(rnd_fh_t)); + if(!fd) { + errno = ENOMEM; + return NULL; + } /* Fill in the filehandle struct */ fd->mode = mode; - realmode = mode & O_MODE_MASK; - - /* We only allow reading, not writing */ - if(realmode != O_RDONLY) { - free(fd); - return NULL; - } - return fd; } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |