From: John Hodge Date: Sun, 9 Mar 2014 07:04:14 +0000 (+0800) Subject: Kernel/MMap - Fix off-by-one error causing junk mappings X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5a3b2a481480b7e061789866df9c6205fa609524;p=tpg%2Facess2.git Kernel/MMap - Fix off-by-one error causing junk mappings --- diff --git a/KernelLand/Kernel/vfs/mmap.c b/KernelLand/Kernel/vfs/mmap.c index 591ae287..b6d5c2d9 100644 --- a/KernelLand/Kernel/vfs/mmap.c +++ b/KernelLand/Kernel/vfs/mmap.c @@ -71,7 +71,7 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, // - Sorted list of 16 page blocks for( pb = h->Node->MMapInfo, prev = NULL; - pb && pb->BaseOffset + MMAP_PAGES_PER_BLOCK < pagenum; + pb && pb->BaseOffset + MMAP_PAGES_PER_BLOCK <= pagenum; prev = pb, pb = pb->Next ) ; @@ -98,6 +98,8 @@ void *VFS_MMap(void *DestHint, size_t Length, int Protection, int Flags, int FD, // - Map (and allocate) pages while( npages -- ) { + assert( pagenum >= pb->BaseOffset ); + assert( pagenum - pb->BaseOffset < MMAP_PAGES_PER_BLOCK ); if( MM_GetPhysAddr( mapping_dest ) == 0 ) { if( pb->PhysAddrs[pagenum - pb->BaseOffset] == 0 )