#include <stdio.h>
#include <string.h>
#include <assert.h>

/*
 * gcc -Wall testassert.c -o test
 * ./test aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 * test: testassert.c:25: main: Assertion `len < sizeof(buf)' failed.
 * Aborted
 *
 * gcc -Wall -DNDEBUG testassert.c -o test
 * ./test aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 * test: stack smashing attack in function main()
 * Segmentation fault
 *
 * Notice? You just removed one layer of protection.
 */


int main(int argc, char **argv)
{
        char buf[16];
        size_t len;

        if ( argc != 2 )
                return -1;
        
        len = strlen(argv[1]);

        /*
         * replace this in the context of a complex
         * program where input len can only be lower
         * than sizeof(buf), appart if there is a bug
         * somewhere in the code. In order to make sure
         * there is no bug, the developer use an assert.
         *
         * Removing this assert could lead to very bad
         * result if the bug is present (which won't be
         * the case in the big majority of case - but still).
         */
        assert(len < sizeof(buf));
        memcpy(buf, argv[1], strlen(argv[1]));

        return 0;
}
