2011.01.11 16:38 "Re: [Tiff] Missing mkstemp() on Visual Studio 2008", by Igor Skochinsky
On Tue, Jan 11, 2011 at 17:18, Olivier Paquet <firstname.lastname@example.org> wrote:
On Tue, Jan 11, 2011 at 10:41 AM, Edward Lam <email@example.com> wrote:
On 1/10/2011 7:01 PM, Igor Skochinsky wrote:
Use instead tmpnam() followed by fopen() with mode "w+bTD" (write, binary, temporary, delete on close).
Good point. However, doesn't using tmpnam() will re-introduce the
possibility of a TOCTOU attack? It took me a while to find the current
CERT recommendation on this . The sad state of affairs as I read it
seems that there is no 100% secure way to create temporary files on
Not if you open using CreateFile() with the CREATE_NEW disposition which causes failure if the file exists. And of course also FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE. Then you _open_osfhandle() and fdopen(). It's a mess but it works.
You can skip one step and use _open() or _sopen() with _O_CREAT | _O_EXCL (this adds CREATE_NEW), _O_TEMPORARY (FILE_FLAG_DELETE_ON_CLOSE) and _O_SHORT_LIVED (FILE_ATTRIBUTE_TEMPORARY).