Alice wrote a heap management library, and she uses the following data structures to manage heap:
struct heap_sector {
int size; // size of the heap sector
char *sector; // pointer to the first char
struct heap_sector *prev; // pointer to previous sector
struct heap_sector *next; // pointer to next sector
};
struct heap_sector *heap_free; // pointer to the list of free heap memory
struct heap_sector *heap_used; // pointer to the list of used heap memory
And use the following logic to manage memory:
• heap used is initialized as NULL, and heap free is initialised to the first available byte;
• malloc(int n) function always allocates the first a few memory sectors whose size is larger
than sizeof(struct heap sector) + 1 (until the total size equals to n) to user process,
and moves the memory from heap free to heap used; if there is no enough space to allocate,
it returns NULL;
• free(char* h) will free the corresponding heap and move the memory from heap used to
heap free.
Answer the following questions:
Please write the pseudo code for malloc(int n) and free(char* h);
• The design is potentially vulnerable to integer overflow. Please explain how this may happen,
and how your pseudo code avoids this problem.
• The design is potentially vulnerable to heap overflow. Please explain how it may happen and
how your pseudo code avoids such problems.
• The design is potentially vulnerable to off-by-one attack. Please explain how this attack may
happen and how your pseudo code avoids such problems.
• The design is potentially vulnerable to TOCTTOU problem. Please explain how it may
happen and how your design avoids such problems.
• Users may free the allocated memory twice or multiple times. Please explain how your design
can prevent this.
Hi there,
I'm bidding on your project "Heap Overflow"
please leave a message on my chat so we can discuss the budget and deadline of the project. I have read your project description and i'm confident i can do this project for you perfectly. Thanks
Note: This is not an automated bid and i'm ready to discuss your project right now.
..