Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Buffer Overflow Attack with Int

char c[10];
int value = 1;

Why the value changes to 0 until I enter 12 chars? Why is 12 not 10 or 11? (I know the terminator and how it pushed to the next memory space)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Objects of a given type are typically placed at memory locations that are a multiple of the object size, i.e. the object is aligned to a boundary matching its size.

An int is typically 4 bytes in size. If c is placed before value in memory, and if c started at a 4 byte offset, then there will be two bytes of padding between them. This would explain why value doesn’t get overwritten unless more than 12 bytes or more are written to c.

Note also that this is all undefined behavior as far as the C standard is concerned, however for the purpose of exploiting vulnerabilities it can be useful to examine what specific implementations do under certain conditions.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading