(1a) Sketch the following C struct, clearly showing the size and position of each member when compiled on x64. Also show the alignment padding that may be required between members and/or at the end of the struct.
struct s_sun {
char water;
short int rain;
short int wind;
unsigned cow;
} sun;
(1b) What is the overall alignment requirement of the struct?
(2a) Consider the following C code which is compiled and run on x64. The procedure prints a prompt string to the terminal then reads a line of input using gets.
char ask()
{ char buf[5];
puts(“Yes or no? “);
gets(buf);
return buf[0]; }
A programmer has examined the assembly code and sketched the stack frame as follows. (The lowest byte of each quadword is on the right.)
return address (8 bytes), unused (3 bytes), buf (5 bytes) ✛ %rsp
Based on the above information, how many characters can be typed as the input line without overwriting the return address on the stack? Do not count the newline as one of the input characters.
(2b) Write an attack input line that would cause the program to execute a procedure at address 0x742B4F31. Briefly explain your answer.