[ipxe-devel] [PATCH v1 2/2] memtop_umalloc: take alignment into account when checking boundaries

David Decotigny decot+ext at google.com
Wed Jan 15 08:19:43 UTC 2020


From: David Decotigny <ddecotig at gmail.com>


---
 src/arch/x86/interface/pcbios/memtop_umalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/arch/x86/interface/pcbios/memtop_umalloc.c b/src/arch/x86/interface/pcbios/memtop_umalloc.c
index d7b82189..1d3f40a1 100644
--- a/src/arch/x86/interface/pcbios/memtop_umalloc.c
+++ b/src/arch/x86/interface/pcbios/memtop_umalloc.c
@@ -190,14 +190,14 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
 	/* Expand/shrink block if possible */
 	if ( ptr == bottom ) {
 		/* Update block */
-		if ( new_size > ( heap_size + extmem.size ) ) {
-			DBG ( "EXTMEM out of space\n" );
-			return UNULL;
-		}
 		new = userptr_add ( ptr, - ( new_size - extmem.size ) );
 		align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) );
 		new_size += align;
 		new = userptr_add ( new, -align );
+		if ( new_size > ( heap_size + extmem.size ) ) {
+			DBG ( "EXTMEM out of space\n" );
+			return UNULL;
+		}
 		DBG ( "EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n",
 		      user_to_phys ( ptr, 0 ),
 		      user_to_phys ( ptr, extmem.size ),
-- 
2.25.0.rc1.283.g88dfdc4193-goog




More information about the ipxe-devel mailing list