Question: Suppose we have a function called getbuf(), that defines a buffer (character array) and then makes a call to Gets(buf) to read in a character

Suppose we have a function called getbuf(), that defines a buffer (character array) and then makes a call to Gets(buf) to read in a character string. See code below. #define BUFFER SIZE 32 int getbuf() char buf BUFFER_SIZE); Gets(buf); return 1;} The function Gets() is similar to the standard library function gets()-it reads a string from standard input (terminated by ' ' or end-of-file) and stores the string (along with a null terminator) at the specified destination. In this code, you can see that the destination is an array buf having sufficient space for 32 characters. Gets() (and gets()) grabs a string off the input stream and stores it into its destination address (in this case buf. However, Gets() has no way of determining whether but is large enough to store the whole input. It simply copies the entire input string, possibly overrunning the bounds of the storage allocated at the destination. We want to see why this can be a problem. Suppose we have a function test that calls getbufo void test() int val; val = getbuf(); printf("No exploit. Getbuf returned 0x%x ", val); What we want you to do is diagram what values are on the stack before getbuf() calls Gets() and after getbuf() calls Gets(). These two diagrams should show where the frames for the function. In addition you should detail where the buffer buf and other important values like return addresses are located on the stack. For the diagram showing what happens after Gets() is called, you should assume that a string greater than 32 characters is entered (say "We need a longer string to showcase the problem Your second diagram of the stack should explicitly show where this string is stored on the stack. Suppose we have a function called getbuf(), that defines a buffer (character array) and then makes a call to Gets(buf) to read in a character string. See code below. #define BUFFER SIZE 32 int getbuf() char buf BUFFER_SIZE); Gets(buf); return 1;} The function Gets() is similar to the standard library function gets()-it reads a string from standard input (terminated by ' ' or end-of-file) and stores the string (along with a null terminator) at the specified destination. In this code, you can see that the destination is an array buf having sufficient space for 32 characters. Gets() (and gets()) grabs a string off the input stream and stores it into its destination address (in this case buf. However, Gets() has no way of determining whether but is large enough to store the whole input. It simply copies the entire input string, possibly overrunning the bounds of the storage allocated at the destination. We want to see why this can be a problem. Suppose we have a function test that calls getbufo void test() int val; val = getbuf(); printf("No exploit. Getbuf returned 0x%x ", val); What we want you to do is diagram what values are on the stack before getbuf() calls Gets() and after getbuf() calls Gets(). These two diagrams should show where the frames for the function. In addition you should detail where the buffer buf and other important values like return addresses are located on the stack. For the diagram showing what happens after Gets() is called, you should assume that a string greater than 32 characters is entered (say "We need a longer string to showcase the problem Your second diagram of the stack should explicitly show where this string is stored on the stack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
