Quote:
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[]){
char buffer[512];
if(argc < 2){
printf("Buggy program!!\n");
printf("Usage: %s <string>\n",argv[0]);
exit(0);
}
strcpy(buffer,argv[1]);
printf("You typed: %s!!\n",buffer);
return 0;
}
This is the most classical one. strcpy copies argv to buffer, without checking its size.
Quote:
#include <stdio.h>
#include <string.h>
#define TAMANHO 100
main(int argc, char *argv[])
{
char nick[TAMANHO];
char *digitado;
if(argc < 2){
printf("Buggy program 2!!\n");
printf("Usage: %s <seu_nick>\n",argv[0]);
exit(0);
}
digitado = argv[1];
strcpy(nick,digitado);
if(!strcmp(nick,"hacko")){
printf("Welcome, master!!\n");
return 0;
}
else{
printf("Get out!!You are a newbie!!\n");
printf("Only hackos have access!!\n");
return 0;
}
}
Digitado=typed , and tamanho=size. Now you know some Portuguese.. :D. Congratulations!