I turned on the -Wstack-protector warning when compiling a project I'm working on (a commercial C ++ multi-platform engine that compiles on Mac OS X 10.6 with GCC 4.2). This flag warns about functions that will not be protected from breaking the stack, even if -fstack-protector enabled. GCC generates some warnings when creating a project:
non-protective function: without a buffer of at least 8 bytes in length
not protecting local variables: variable-length buffer
For the first warning, I found that you can configure the minimum size that a buffer should have when used in a function so that this function is protected from stack splitting: --param ssp-buffer-size=X can be used, where X is 8 by default and maybe like 1.
In the second warning, I cannot suppress its occurrences unless I stop using the -Wstack-protector .
- When should you use the
-fstack-protector ? (as, for example, during dev or just when tracking errors?) - When should you use
-fstack-protector-all ? - What does the
-Wstack-protector tell me? Is this an assumption that I am decreasing the minimum buffer size? - If so, are there any flaws to putting the size at 1?
- It seems that
-Wstack-protector is not the flag that you always want to turn on if you want to build without warning. Is it correct?
c ++ gcc stack protection
Guillaume Oct 27 '09 at 9:40 2009-10-27 09:40
source share