Subject: Re: bug#11100: Racy code in copy.c

From: Jim Meyering <[email-masked]>
Date: Fri, 04 May 2012 16:58:53 +0200

Eric Blake wrote:

> On 05/04/2012 08:47 AM, Jim Meyering wrote:
>>
>> * src/copy.c (copy_reg): In a narrow race (stat sees dest, yet
>> open-without-O_CREAT fails with ENOENT), retry the open with O_CREAT.
>> Reported by Philipp Thomas and Neil F. Brown in
>> http://debbugs.gnu.org/11100
>
> Question - when we retry with adding O_CREAT, should we also add O_EXCL?
>  That is, we already lost the race once, but the O_EXCL will ensure that
> we don't lose the race a second time and that we really are creating a file.

I was concerned about that, too, but noted
it's already always done in the O_CREAT/*new_dst path:

  if (*new_dst)
    {
    open_with_O_CREAT:;

      int open_flags = O_WRONLY | O_CREAT | O_BINARY;
      dest_desc = open (dst_name, open_flags | O_EXCL,
                        dst_mode & ~omitted_permissions);