Hi people, my names Mark i'm new to this forum. I have been asked to listen vulnerabilities in this piece of code, focusing on buffer overflow etc. I am struggling to find what is wrong if anyone could please help me identify what is wrong!
here is the code:
#include <stdio.h>
#include <string.h>
const int NUM_USERS = 5; /*length of userDetails list*/
/* list of pairs of form {user, pasWd} */
char* userDetails[NUM_USERS][2] = { {"fred", "fred"}, {"bill", "bill"}, {"george", "george"}, {"yoko", "yoko"}, {"liane", "liane"} );
/* function to test input details */
bool isRecognised(char aName[], char aPword[]) {
int count = 0;
bool result = false;
while (count < NUM_USERS && result == false) {
if( strcmp((char*)userDetails[count][0], aName) ==0 &&
strcmp((char*)userDetails[count][1],aPword)==0 )
result = true; // end if
++count;
} // end while
return result;
}// end isRecognised
int main (void) {
char uName[10], pWord[10];
bool recognised;
int numAttempts = 0;
puts("please enter username & password ");
gets(uName);
gets(pWord);
gets does not let you specify a limit on how many characters are to be read, so you must be careful with the size of the array pointed by str to avoid buffer overflows.
Are you restricted to C? This would be so much easier if you weren't.
All the same, if you are including string.h, you should be able to use the declaration string password ="";//correct me if this is restricted to C++
and then using conio.h, you could also declare a character, use
1 2 3 4 5 6 7
ch=_getch();
while(ch != 13 /*13 is enter*/)
{
password.push_back(ch);
printf("*");
ch=_getch();//once again, correct me if this is C++ only, i havent used
//C in forever