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:
copilot-swe-agent[bot]
2025-12-28 23:09:23 +00:00
parent c81d08c2a8
commit 0093b10138

View File

@@ -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--;