Hint: why wouldn't this be vulnerable to a buffer overflow?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define CONSTANT 2
int main( int argc, char** argv )
{
int unused = CONSTANT;
char buffer[ CONSTANT ];
if( argc != 2 )
{
printf( "Overflow This!\n" );
printf( "Usage: %s <text>\n", *argv );
return EXIT_FAILURE;
}
strncpy( buffer, argv[ 1 ], sizeof( buffer ) );
buffer[ sizeof( buffer ) - 1 ] = 0;
printf( "Unused = %d, Buffer: '%s'\n", unused, buffer );
return EXIT_SUCCESS;
}
If you can answer that, then you can answer the original questions, I think.