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 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
Answer a In this code snippet theres a vulnerability due to the race condition between the stat and ... View full answer
Get step-by-step solutions from verified subject matter experts
