On 01/30/2017 03:49 AM, Steve D'Aprano wrote:
This code contains a Time Of Check to Time Of Use bug:

    if os.path.exists(destination)
        raise ValueError('destination already exists')
    os.rename(oldname, destination)


In the microsecond between checking for the existence of the destination and
actually doing the rename, it is possible that another process may create
the destination, resulting in data loss.

Apart from keeping my fingers crossed, how should I fix this TOCTOU bug?


There is a rather extensive discussion of this problem (with no good cross-platform solution if I remember correctly):

https://mail.python.org/pipermail/python-ideas/2011-August/011131.html

which is related to http://bugs.python.org/issue12741

Wolfgang

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to