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

1 Expert Approved Answer
Step: 1 Unlock

Answers The above problem can be solved in the following steps STEP 1 First change ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!