I\'m new to C. Sorry if this has already been answered, I could\'n find a straight answer, so here we go..
I\'m trying to understand how malloc() works in C. I have this
Yes writing more data into an allocated buffer is a buffer overflow. However there is no buffer overflow check in C and if there happens to be valid memory after your buffer than your code will appear to work correctly.
However what you have done is write into memory that you don't own and likely have corrupted the heap. Your next call to free
or malloc
will likely crash, or if not the next call, some later call could crash, or you could get lucky and malloc
handed you a larger buffer than you requested, in which case you'll never see an issue.