Tcl Source Code

View Ticket
Login
Ticket UUID: 27b682284974d0cdf4686f31adcb9ee39a0befa6
Title: file delete can return an error if file was already deleted
Type: Bug Created on: 2018-04-06 14:05:10
Submitter: raimue Assigned to: nobody
Subsystem: 37. File System Severity: Severe
Priority: 5 Medium Last modified: 2018-04-09 10:12:02
Status: Closed Closed by: sebres
Resolution: Fixed Closed on: 2018-04-09 10:12:02
Version: 8.5
Description:
The 'file delete' command can fail with "no such file or directory", but it is
supposed to return successfully in this case.

This can happen when another process removes the file exactly between the
system calls to stat(2) and unlink(2) in TclFileDeleteCmd(), which is a classic
TOCTTOU race condition.

I will attach a patch that adds an additional check for the result of
Tcl_FSDeleteFile() and if it was ENOENT, the command is considered successful.
User Comments:
sebres added on 2018-04-06 17:37:45:

I've fixed it in [5acb57c7aec45e05] (although other 8.5th branch, but if not whole accepted this commit can be easy cherry-picked into core-8-5-branch).

Deviations from suggested patch: I've rewritten it also to catch the same race-condition in case of deleted directory.

Thanks you Rainer.


raimue added on 2018-04-06 18:44:52:
Thank you for the quick response. Applying the same change to
directories makes sense, it just did not occur to me.

Looking at the patch, I see you removed
  result = TCL_ERROR;
before the break statement, but I think this was actually needed as
Tcl_FSRemoveDirectory() and Tcl_FSDeleteFile() return -1 on error.

sebres added on 2018-04-09 10:12:02:

I was confused by the comment header of both. Corresponding it Tcl_FSDeleteFile as well as Tcl_FSRemoveDirectory returns "Standard Tcl error code" (what is indeed wrong).

So fixed now in [6627aeef8ecda182] for TclFileDeleteCmd.

But I guess we have to fix all the comments "Returns" in tclIOUtil.c.


Attachments: