Can anyone give out some example code which will make malloc signal an sigsegv?
Googled that, heap corruption may lead to an sigsegv in malloc, but I can’t understand that.
Thanks a lot.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s a decent chance this will cause problems, though it might be
free()rather thanmalloc()that gives you the SIGSEGV.You might get the crash in
malloc()with:This overwrites 32 bytes before and after the allocated memory, which is likely to corrupt any control information if it is stored contiguously will the allocated memory (which is usually the case). Using zeroes maximizes the chance that you’ll get a null pointer access. You could choose an alternative value to write over the data which might means that sizes appear larger than zero (where zero sizes might protect you from memory access).
Of course, this is all completely undefined behaviour; you might get the crash in
memset(), or you might not get a crash at all.