2

I found out that for prevent to buffer overflow I can use that instruction (gcc -fstack-protector -S XXX.c).

For example, I have a file that name is test.c and that file has a buffer overflow, (ex. there is char buf[10]; but I want to strcpy(buf,"HelloUnixAndLinux"))

In that case

$gcc -fstack-protector -S test.c
$cat test.s

will check the buffer and let me know as print out something long display including stack_chk_fail.

I want to know about those instructions but there is nothing explain about it. (I just found out that way on Internet without any effect)

I want to know that

  1. Those option always prevent buffer overflow automatically? (ex. if some function can lead to buffer overflow, automatically not process strcpy etc)

  2. Is there any way to check is my GCC provide a tool for checking stack smashing? Mine is GCC 4.4.6 Red Hat 4.4.6-4.

  3. Is there any way to display warning about buffer overflow after ./a.out?

cathy_q
  • 21
  • 1
  • The has been previously answered [**When and how to use GCC's stack protection feature?**](http://stackoverflow.com/questions/1629685/when-and-how-to-use-gccs-stack-protection-feature) – David C. Rankin Nov 19 '14 at 03:28
  • Even though the duplicate question is marked C++ rather than C, it applies to both the C and C++ compilers in the GCC (GNU Compiler Collection). The options do not prevent buffer overflows; they add checking code to detect buffer overflows more quickly and reliably than not including the check. You can try using the options with your compiler; if they don't work, you need to get a more modern compiler. There'll be a runtime error if you have a buffer overflow. – Jonathan Leffler Nov 19 '14 at 07:27
  • I checked that explanation but still can't get the idea of that option. Do I have to type gcc -fstack-protector -S XXX.c everytime when I try to compile the program to get warning ? – cathy_q Nov 20 '14 at 02:41

0 Answers0