I have declared two variables (one global and other local) in a simple C program, apart from two arrays having different sizes data. I cause a buffer overflow using strcpy() routine before making a return 0; call. And I see segmentation fault error on the terminal screen.
I know that after receiving this SIGSEGV signal, system takes a core dump of process memory and terminates that process, but does system do clean-up (zero-out) of stack/heap memory and other sections like BSS segment, text segment etc?
I guess, in normal termination of a process, system does clean-up (zero-out) of memory but I am not so sure.
I am using Ubunutu 10.12 and gcc to run the program.
When a Linux process terminates (either normally, by calling the
_exitsyscall, e.g. by returning frommain, or thru a signal likeSIGSEGV), its address space ceases to exist.In practice, the kernel does not zero the former process’ memory, it just add the relevant pages to some set of free pages and will reuse these pages later. When reusing a page it will clear it or fill it with appropriate content. All this happens inside the kernel, applications only see appropriately filled (or cleared) pages.
You should read more about virtual memory and I invite you to read some good advanced unix programming and advanced linux programming books.
Processes see only virtual memory, their address space is set up thru the execve(2) syscall and may be changed, e.g. with mmap(2) syscall.