Fernando J. Pereda’s blag

August 24, 2008

Security Trivia IV

Filed under: blag — Tags: , — Fernando J. Pereda @ 2:02 pm

This one is easy and sweet. Your goal is to make this program crash and explain why that happened, good luck:

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

int main(int argc, char *argv[])
{
	if (argc != 4) {
		fprintf(stderr, "DIAF\n");
		return EXIT_FAILURE;
	}

	char c[3];
	unsigned i;
	for (i = 0; i < sizeof(c); i++)
		c[i] = atoi(argv[i + 1]);

	if (c[0] + c[1] + c[2] == 0) {
		fprintf(stderr, "No no\n");
		return EXIT_FAILURE;
	}

	c[1] += c[0] + c[2];
	printf("%d\n", c[0]/c[1]);

	return EXIT_SUCCESS;
}

Before spoling your own fun looking at the comments, try to do it yourself. Really, it is easy, and will make you understand C better.

— ferdy

Advertisements

Create a free website or blog at WordPress.com.