Heap Bug In JamesM's Tutorials

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Heap Bug In JamesM's Tutorials

Post by Creature »

Hello,

I just wanted to say this for other developers using JamesM's tutorials. I'm not sure but, isn't this piece of code:

Code: Select all

if ((u32int)hole_footer < heap->end_address)
       {
           hole_footer->magic = HEAP_MAGIC;
           hole_footer->header = hole_header;
       }
In chapter 7 (7.4.2.2. Allocation) supposed to be this:

Code: Select all

if (((u32int)hole_footer + sizeof(footer_t)) < heap->end_address)
       {
           hole_footer->magic = HEAP_MAGIC;
           hole_footer->header = hole_header;
       }
Because JamesM checks if writing the footer of the hole will go past the ending address of the heap, but if the starting address of the hole footer is just before the ending address, but the structure's size reaches beyond the ending address, a page-fault will/might occur. So I think this is a bug.

Can you give me any feedback on this (I'm not really a guru in heap-related things).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Heap Bug In JamesM's Tutorials

Post by JamesM »

Probably a valid bug, I'll have another look when I'm not drunk!
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Heap Bug In JamesM's Tutorials

Post by AJ »

Hi,

From what you say it looks valid, but that operator would also need to change from '<' to '<=', because for the last entry, hole_footer + sizeof(footer_t) will equal heap->end_address.

Cheers,
Adam
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Heap Bug In JamesM's Tutorials

Post by Creature »

AJ wrote:Hi,

From what you say it looks valid, but that operator would also need to change from '<' to '<=', because for the last entry, hole_footer + sizeof(footer_t) will equal heap->end_address.

Cheers,
Adam
True, otherwise it won't be written if it still ends at the end-address, while it should.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
Post Reply