mirror of
https://github.com/johndoe6345789/MetalOS.git
synced 2026-04-24 13:45:02 +00:00
Add bounds checking to prevent buffer overflow in bitmap access
- Add safety check in allocPage() before accessing pageBitmap - Add safety check in freePage() before accessing pageBitmap - Prevents potential buffer overflow when bitmap size limits are reached Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -74,6 +74,11 @@ void* PhysicalMemoryManager::allocPage() {
|
||||
uint64_t byte = i / 8;
|
||||
uint64_t bit = i % 8;
|
||||
|
||||
// Bounds check to prevent buffer overflow
|
||||
if (byte >= BITMAP_SIZE) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(pageBitmap[byte] & (1 << bit))) {
|
||||
// Mark as used
|
||||
pageBitmap[byte] |= (1 << bit);
|
||||
@@ -111,6 +116,11 @@ void PhysicalMemoryManager::freePage(void* page) {
|
||||
uint64_t byte = pageIdx / 8;
|
||||
uint64_t bit = pageIdx % 8;
|
||||
|
||||
// Bounds check to prevent buffer overflow
|
||||
if (byte >= BITMAP_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark as free
|
||||
pageBitmap[byte] &= ~(1 << bit);
|
||||
usedPages--;
|
||||
|
||||
Reference in New Issue
Block a user