Skip to content

Commit

Permalink
Fix a reference being used after being invalidated
Browse files Browse the repository at this point in the history
Your classic use-after-free bug.
  • Loading branch information
ISSOtm committed Mar 12, 2024
1 parent 81ed5fe commit 74026cd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/link/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ static void placeSection(Section &section) {
.size =
(uint16_t)(freeSpace.address + freeSpace.size - section.org - section.size)}
);
// **`freeSpace` cannot be reused from this point on**, because `bankMem.insert`
// invalidates all references to itself!

// Resize the original space (address is unmodified)
freeSpace.size = section.org - freeSpace.address;
bankMem[spaceIdx].size = section.org - bankMem[spaceIdx].address;
} else {
// The amount of free spaces doesn't change: resize!
freeSpace.size -= section.size;
Expand Down

0 comments on commit 74026cd

Please sign in to comment.