➜ ~/Desktop/20171201-fastbin$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
➜ ~/Desktop/20171201-fastbin$ uname -a
Linux thinkpad 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
测试程序
gcc xx.c -o xx
#include<stdio.h>
#include<unistd.h>
void main()
{
int a=1;
char b[104];
int c = 2;
read(STDIN_FILENO,b,100);
printf("end\n");
}
man gcc>
-fstack-protector
Emit extra code to check for buffer overflows, such as stack
smashing attacks. This is done by adding a guard variable to
functions with vulnerable objects. This includes functions that
call "alloca", and functions with buffers larger than 8 bytes. The
guards are initialized when a function is entered and then checked
when the function exits. If a guard check fails, an error message
is printed and the program exits.
-fstack-protector-all
Like -fstack-protector except that all functions are protected.
-fstack-protector-strong
Like -fstack-protector but includes additional functions to be
protected --- those that have local array definitions, or have
references to local frame addresses.
-fstack-protector-explicit
Like -fstack-protector but only protects those functions which have
the "stack_protect" attribute
-fstdarg-opt
Optimize the prologue of variadic argument functions with respect
to usage of those arguments.
NOTE: In Ubuntu 14.10 and later versions, -fstack-protector-strong
is enabled by default for C, C++, ObjC, ObjC++, if none of
-fno-stack-protector, -nostdlib, nor -ffreestanding are found.