- Q4 A Consider The Program Shown Below Const Int Max 256 Class A Char Prefix 4 A Self Char Fname Char Lname 1 (63.14 KiB) Viewed 15 times
Q4. (a) Consider the program shown below: const int MAX=256; class A{ char prefix[4]; A* self; char* fname; char* lname;
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Q4. (a) Consider the program shown below: const int MAX=256; class A{ char prefix[4]; A* self; char* fname; char* lname;
Q4. (a) Consider the program shown below: const int MAX=256; class A{ char prefix[4]; A* self; char* fname; char* lname; public: A(char* pl, char* p2) { self = this; fname = pl; Iname=p2; } virtual void print() { cout << "Hello: "<< prefix <<<fname << Iname << endl; } virtual void getname() { getns (fname, MAX); //getns stops reading after at most MAX characters getns (lname, MAX); gets (prefix); self->print(); } }; void work (Ap) { p->getName(); } char pl[MAX]; char p2 [MAX]; A y (p1, p2); main(int ac, char** av) { work (&y); } The following is given: addresses are 8 bytes long • characters are 1 byte long Virtual function table entries are 8 bytes long • stack frames are organized so the stack grows from high address to low addresses C++ objects are organized such that a pointer to the virtual function table is stored first (low address) and followed by the object fields in order of declaration. The operating system prevents the execution of code that resides on the stack or heap. i. Draw a diagram of the relevant parts of memory showing variables and other relevant areas labeling bytes with actual or relative addresses. ii. Show a possible code injection attack vector (you may assume that the shell code is given) and explain why it will fail/succeed?