Re: Secure temporary fifo creation
Goswin von Brederlow <brederlo@informatik.uni-tuebingen.de> writes:
> Philippe Troin <phil@fifi.org> writes:
>
> > Not needed... This should be race-free:
> >
> > char *s;
> > while (s = (tempnam("/tmp", "foo")) {
> > if (mknod(s, S_IFIFO|0600, 0) == 0)
> > break;
> > if (errno != EEXIST)
> > /* error */
> > }
> > if (!s)
> > /* error */
>
> What happens if the 'tempnam' is a link to somehwere else? Does mknod
> fail or create the fifo where the link points too?
It fails... The mknod(2) manpage specifies:
If pathname already exists, or is a symlink, this call
fails with an EEXIST error.
So the above code snippet should be safe.
Phil.
Reply to: