Modifier le programme pour avoir un buffer overflow

[Fermé]
Signaler
-
#include <stdio.h>

char user_name[20] = " ";
char password[20] = " ";
char users[][2][20] =
{ { "root", "98765" },
{ "moi", "allo" },
{ "abc", "motdepasse" },
{ "", "" }
};

int check_name()
{
int i;
printf("Nom: "); gets(user_name);
printf("Mot de passe: "); gets(password);

for(i=0; users[i][0][0] != 0; i++)
{
if(strcmp(user_name, users[i][0]) == 0 &&
strcmp(password, users[i][1]) == 0)
return 1;
}
return 0;
}

void logon()
{
printf("Bienvenu sur ce systeme...\n");
exit(1);
}

void reject()
{
printf("Connection fermee!\n");
exit(0);
}
unsigned int i;
main()
{
for(i=(unsigned)-3; i && !check_name(); i++);
if(i>=(unsigned)-2)
logon();
else
reject();
}