简体   繁体   中英

Detecting stack overrun/overwrite in a multi threaded C++ application on Linux

Is it possible for one thread to overwrite memory in another thread's stack? Hence possibly corrupting the return address for example.

If it is possible, are there any debugging tools or other practices to help detecting such problems?

I am talking about C/C++ applications using pthreads on a Linux x86 system.

If you are using your own memory manager to reduce sbrk system call, valgrind may not detect ABW. Because valgrind overrides malloc of libc. If it is the case, you may have to re-link(or compile) your program to use malloc instead of your own memory alloc function.

Besides valgrind, which is a free tool, if you do not mind using commercial tools, purify may be the alternative.

The two tools differ in the way how you use it. With purify, you'll need to re-link your program with libs purify provides. With valgrind, you just run your program through valgrind, no re-linking is needed.

您可以使用GCC Mudflap库/仪器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM