[PATCH v2 1/2] mktemp: avoid removed mktemp()

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Mon Apr 14 10:20:54 UTC 2014


On 13 April 2014 16:41, Denys Vlasenko <vda.linux at googlemail.com> wrote:
> On Tue, Apr 8, 2014 at 3:11 PM, Bernhard Reutner-Fischer
> <rep.dot.nop at gmail.com> wrote:
>> +       if (opts & OPT_d) {
>>                 if (mkdtemp(chp) == NULL)
>>                         goto error;
>> +               if (opts & OPT_u)
>> +                       rmdir(chp);
>
> This is a change in behavior - now we would
> actually create, and then immediately delete the directory
> if run as "mktemp -du".
>
> I have mixed feelings about that.
> Do you think it's ok?

I think it's ok, yes. The race-window is about the same as
before, the creat()/unlink() do make it a bit slower but that
is IMO ok.
An alternative would be to export a uClibc-specific
__gen_tempname() function to avoid all those duplicate implementations
(in busybox, coreutils etc, etc) but i don't really think it's worth the effort
given that only mktemp(1) has something like it's -u and -u
obviously should not be used in the first place (due to races).
I fear that the (IMO) "correct" fix, i.e. removing -u, potentially breaks quite
some scripts, so unlink/rmdir seems to be the least intrusive thing to
do right now.

Makes sense?

thanks,


More information about the busybox mailing list