Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rewrite the program. Get rid of those nasty arrays and replace them with string data types. /* Simple buffer overflow example RJBotting 9/27/2004 Warning this

Rewrite the program. Get rid of those nasty arrays and replace them with string data types. /* Simple buffer overflow example RJBotting 9/27/2004 Warning this is an example with many pieces of insecure code and information. Inspired by INSIDE THE BUFFER OVERFLOW ATTACK: MECHANISM, METHOD, & PREVENTION Mark E. Donaldson, SANS Corporation. April 3, 2002 GSEC Version 1.3 */ #include  #include  #include  #include  #include  using namespace std; void get(char* askfor, int numchars, char* input); void get_password(char* name, char* pwd); int main() { // Change these character arrays to strings. char name[8]; char pwd[8]; char passwd[8]; cout << "Address of name =" << &name <<" "; cout << "Address of pwd =" << &pwd <<" "; cout << "Address of passwd =" << &passwd <<" "; char Name[5]="Name"; char Password[9]="Password"; bool authenticated=false; while(! authenticated) { // input the name here get(Name, 7, name); // get the password pwd for the name get_password(name, pwd); // input a password passwd get(Password, 7, passwd); // cout <>input; return; } void get_password(char* name, char* pwd) { // Yuch! This returns pwd depending on the variable name // Rewrite so it accepts a string name and returns a string if(!strcmp(name,"botting")) strcpy(pwd, "123456"); else if(!strcmp(name,"ernesto")) strcpy(pwd, "765432"); else if(!strcmp(name,"tong")) strcpy(pwd, "234567"); else strcpy(pwd, "qwert"); return; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions