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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!