[MINC-development] patches for tmpnam

Robert VINCENT minc-development@bic.mni.mcgill.ca
Mon, 10 Mar 2003 10:34:19 -0500


Steve,

I thought that having the function create the file avoids the worst
aspects of the race condition, since the file is known to have been
created successfully with relatively secure permissions and ownership.
Closing the file should be immaterial, since the file is known to exist
with owner read/write permissions only.  However, I realize now that it
would be more correct if I used open() with O_EXCL than by using creat(),
since some implementations of creat() will not fail if the file already
exists.

If you prefer that I allocate memory in the function, I'm OK with that, I
just have a preference for functions that force the caller to allocate
the memory (I get fewer memory leaks that way).

	-bert


> It seems to me that you could simplify the logic of the function
> by closing the file in the HAVE_MKSTEMP block, and refraining
> from creating & closing the file in other cases (since it buys you
> nothing).
>
> In addition, you could probably simplify your life if the function
> took no arguments and simply returned a pointer to some malloc()'d
> memory as the current get_temporary_filename() function does.  This
> has two benefits: (a) you wouldn't have to guess at MI_MAX_PATH, and
> (b) you can use strlen() before allocating the memory so you don't
> have to worry about some fool defining TMPDIR to a really long string
> (longer, say, than MI_MAX_PATH).
>
> -S
>
> _______________________________________________
> MINC-development mailing list
> MINC-development@bic.mni.mcgill.ca
> http://www.bic.mni.mcgill.ca/mailman/listinfo/minc-development
>