Question: Consider the following code snippet: if (!stat(file.dat, buf)) return; sleep(10); // abort if file exists fp // sleep for 10 seconds // open file

Consider the following code snippet: if (!stat("file.dat", buf)) return; sleep(10); // abort


Consider the following code snippet: if (!stat("file.dat", buf)) return; sleep(10); // abort if file exists fp // sleep for 10 seconds // open file for write. fopen("file.dat", "w" ); fprintf(fp, "Hello world" ); close(fp); a. Suppose this code is running as a setuid root program. Give an example of how this code can lead to unexpected behavior that could cause a security problem. Hint: try using symbolic links. b. Suppose the sleep(10) is removed from the code above. Could the problem you identified in part (a) still occur? Please explain. c. How would you fix the code to prevent the problem from part (a)?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer a In this code snippet theres a vulnerability due to the race condition between the stat and ... View full answer

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 Programming Questions!