Question: Buffer Overflow Two Fix to the Problem: Change #include to #include Change Password from a char array to a C++ string: string Password; Change the
Buffer Overflow Two Fix to the Problem: Change #include to #include Change Password from a char array to a C++ string: string Password; Change the comparison to be C++ string friendly: if (!Password.compare(“secret”)) Now run the program again typing any six characters and T as the seventh one.
code to change:
#include
#include
using namespace std;
int PasswordOkay() {
char Password[6];
char GoodPassword = 'F';
cin >> Password;
if (!strcmp(Password, "secret"))
GoodPassword = 'T';
return (GoodPassword == 'T');
}
int main() {
cout << "Enter Password:";
if (PasswordOkay())
cout << "Access Granted";
else
cout << "Access Denied";
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Answers The above problem can be solved in the following steps STEP 1 First change ... View full answer
Get step-by-step solutions from verified subject matter experts
