Skip to content

Commit 6458d47

Browse files
committed
Fix realloc by updating the stored Layout. Previously the old Layout was copied over but not updated to account for the new size, resulting in all kinds of UB and memory corruption
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 1181e50 commit 6458d47

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/hyperlight_guest/src/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ pub extern "C" fn hlrealloc(ptr: *mut c_void, size: usize) -> *mut c_void {
8888
// Realloc failed
8989
abort_with_code(ErrorCode::MallocFailed as i32);
9090
} else {
91-
// Return the pointer just after the layout information
92-
// since old layout should still as it would have been copied
91+
// Update the stored Layout, then return ptr to memory right after the Layout.
92+
new_block_start.write(new_layout);
9393
new_block_start.add(1) as *mut c_void
9494
}
9595
}

0 commit comments

Comments
 (0)