From fc7371134c3b43b4382655f3b5447749da12b306 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 7 Aug 2012 17:00:56 +0800 Subject: [PATCH] Modules/LVM - Catches for stupid coding --- KernelLand/Modules/Storage/LVM/volumes.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/KernelLand/Modules/Storage/LVM/volumes.c b/KernelLand/Modules/Storage/LVM/volumes.c index c9ce9a82..cf1a60d1 100644 --- a/KernelLand/Modules/Storage/LVM/volumes.c +++ b/KernelLand/Modules/Storage/LVM/volumes.c @@ -30,6 +30,12 @@ int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t tLVM_Format *fmt; void *first_block; + if( BlockCount == 0 || BlockSize == 0 ) { + Log_Error("LVM", "BlockSize(0x%x)/BlockCount(0x%x) invalid in LVM_AddVolume", + BlockSize, BlockCount); + return 1; + } + dummy_vol.Type = Type; dummy_vol.Ptr = Ptr; dummy_vol.BlockCount = BlockCount; @@ -37,6 +43,10 @@ int LVM_AddVolume(const tLVM_VolType *Type, const char *Name, void *Ptr, size_t // Read the first block of the volume first_block = malloc(BlockSize); + if( !first_block ) { + Log_Error("VLM", "LVM_AddVolume - malloc error on %i bytes", BlockSize); + return -1; + } Type->Read(Ptr, 0, 1, first_block); // Determine Format -- 2.20.1