Finding Memory leaking, Stack and Heap overflow

When you access an array index, C and C++ don’t do bound checking. Segmentation faults only happen when you try to read or write to a page that was not allocated (or try to do something on a page which isn’t permitted, e.g. trying to write to a read-only page), but since pages are usually pretty big (multiples of a few kilobytes), it often leaves you with lots of room to overflow.

If your array is on the stack, it can be even worse as the stack is usually pretty large (up to several megabytes). This is also the cause of security concerns: writing past the bounds of an array on the stack may overwrite the return address of the function
and lead to arbitrary code execution (the famous “buffer overflow” security breaches).

By setting the following flags you can find the issue:

Example:

References: [1]

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x