Page 1 of 1

Q4. (a) Consider the program shown below: const int MAX=256; class A{ char prefix [4]; A* self; char* fname; char* lname

Posted: Thu May 26, 2022 9:48 am
by answerhappygod
Q4 A Consider The Program Shown Below Const Int Max 256 Class A Char Prefix 4 A Self Char Fname Char Lname 1
Q4 A Consider The Program Shown Below Const Int Max 256 Class A Char Prefix 4 A Self Char Fname Char Lname 1 (145.73 KiB) Viewed 20 times
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* p1, char* p2) { self this; fname = p1; lname = p2; } virtual void print() { cout << "Hello: << prefix << fname << lname << endl; } virtual void getname() { getns (fname, MAX); //getns stops reading after at most MAX characters getns (lname, MAX); gets (prefix); self->print(); }; void work (A* p) { p->getName(); } char p1 [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? }