Question: Given this code, answer the following questions: void function(char *str) { char buffer[16]; strcpy(buffer, str); printf(%s, buffer); } void main() { char large_string[256]; int i;
Given this code, answer the following questions:
void function(char *str)
{ char buffer[16];
strcpy(buffer, str);
printf("%s", buffer); }
void main()
{ char large_string[256];
int i;
for( i = 0; i < 255; i++)
large_string[i] = 'A' + i;
function(large_string); }
1. When function returns, a segment fault will be generated at which address? Why?
2. How would you fix the vulnerability using strncpy?
3. How many character are in the printed out string? Why?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
