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

int main(int argc, char *argv[])
{
	const char *p;
	char arr[100];
	int maxsize = sizeof(arr)-1;
	int i, size;

	if (argc < 2) {
		printf("Usage: ./signed 123456789012\n");
		return 0;
	}

	/* manually parse the number */
	size = 0;
	for (p = argv[1]; *p != '\0'; p++) {
		if (*p < '0' || *p > '9') {
			printf("Usage: ./signed 123456789012\n");
			return 1;
		}
		size = size*10 + *p - '0';
	}

	if (size > maxsize)
		size = maxsize;

	printf("Feed %d bytes\n", size);

	/* even while this works fine.. */
	for (i = 0; i < size; i++)
		arr[i] = getc(stdin);

	/* ..here we can write \0 to arbitrary position in memory - could be
	   diffucult to exploit, but still may be possible. */
	arr[i] = '\0';

	return 0;
}
