I have heard about a buffer overflow and I would like to know how to cause one.
Can someone show me a small buffer overflow example? New(And what they are used for?)
This is a general comment about the answers you received. For example:
int main(int argc, char *argv[]) { char buffer[10]; strcpy(buffer, argv[1]); }
And:
int main(int argc, const char* argv[]) { char buf[10]; memset(buf, 0, 11); return 0; }
On modern Linux platforms, this may not work as expected or intended. It may not work because of the FORTIFY_SOURCE security feature.
FORTIFY_SOURCE uses "safer" variants of high risk functions like memcpy and strcpy. The compiler uses the safer variants when it can deduce the destination buffer size. If the copy would exceed the destination buffer size, then the program calls abort().
To disable FORTIFY_SOURCE for your testing, you should compile the program with -U_FORTIFY_SOURCE or -D_FORTIFY_SOURCE=0.