[sane-devel] Temp file races

Tim Waugh twaugh at redhat.com
Fri Jan 18 08:43:35 GMT 2002


On Fri, Jan 18, 2002 at 12:25:34AM +0100, abel deuring wrote:

> Henning Meier-Geinitz wrote:
> 
> > There are some ways to avoid this:
> > 
> > * don't use temp files at all
> > * don't create them in a world writeable directory, use the HOME directory
> > * use open together with the flag O_EXCL and O_CREAT to make sure, that the
> >   file (or a symlink) doesn't exist.
> > * use mkstemp. This is probably the best but I don't know how many platforms
> >   support it.
> 
> What about a library function?

Indeed: mkstemp(3) is there for you to use (and you can use fdopen(3)
on the file descriptor to get a FILE*).  Also there is tmpfile(3),
which should also be safe.

Basically: if it's a temporary file, use one of those two functions,
and not open or fopen.

Tim.
*/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/sane-devel/attachments/20020118/a681f9e9/attachment.sig>


More information about the sane-devel mailing list