/*
 *
 * cc -o vuln vun.c
 * ./vuln 1234567890123456
 *
 */

#include <stdio.h>

unsigned long __guard = 0UL;

int main(int argc, char **argv, char **envp, char **auxv) {
#ifdef VULN_HEAP
	char *buf = (char *) malloc(10);
#else
	char buf[10] = "";
#endif
	char buf1[] = "01234567890123456789";
	printf("%p main(argc=%p, argv=%p, envp=%p, auxv=%p) __guard=%p", 
		&main, &argc, &argv, &envp, &auxv, &__guard);
	puts("");
	fflush(stdout);
	if (argc > 1) {
		if (strcmp(argv[1], "-a") == 0) {
			while(1) {
				printf("Appending [%d] to a buffer thats [%d] bytes long with a max buffer size of [%d]\n",
					1, strlen(buf)+1, sizeof(buf));
				fflush(stdout);
				strcat(buf, "A");
			}
		}
		printf("Copying [%d] of data into [%d] of space\n",
		strlen(argv[1]), sizeof(buf));
		strcpy(buf, argv[1]);
	} else {
		printf("Triggering an overflow by copying [%d] of data into [%d] of space\n",
			strlen(buf1), sizeof(buf));
		strcpy(buf, buf1);
	}
	return 0;
}
