How it works...
You can see in the program that a file pointer is defined by the name fp. We are expecting that a hacker or malicious user might have created a soft link called file1.txt to the existing file, file2.txt. file2.txt is a sensitive file that we don't want to be overwritten or destroyed. To make the program free from any vulnerability, the unlink() function is invoked to remove any links to the file1.txt. This will avoid overwriting of any sensitive file that might be linked with file1.txt.
Also, the open function is invoked to open the file instead of the traditional fopen function. The open function opens the file1.txt file in write-only mode with the O_CREAT and O_EXCL flags, which will fail the open function if the file already ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access