Milan Stephan
Fotografie & IT

Zurück zur SPiC Übersicht

bufferoverflow.c

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

static long check_password(const char *password);
static void print_exam();

int main(int argc, const char *argv[]) {
	if(argc != 2) {
		fprintf(stderr, "Usage: %s <password>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	if(check_password(argv[1])) {
		fprintf(stdout, "Printing exam...\n");
		print_exam();
		return EXIT_SUCCESS;
	} else {
		fprintf(stderr, "Permission denied\n");
		return EXIT_FAILURE;
	}
}

long check_password(const char *password) {
	long pass = 0;
	char buff[8];

	strcpy(buff, password);

	if(strcmp(buff, "spic")) {
		printf("Wrong Password\n");
	} else {
		printf("Correct Password\n");
		pass = 1;
	}

	return pass;
}

void print_exam(void) {
	printf("  \n");
	printf("  SPiC Klausur SS 2022\n");
	printf("  \n");
	printf("  Aufgabe 1)\n");
	printf("  ...\n");
	printf("  \n");
}