dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Bustamante <dualbus@gmail.com>
To: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>, dash@vger.kernel.org
Subject: Re: Bug? "fstat64(f, &sb) < 0 && S_ISREG(sb.st_mode)"
Date: Tue, 25 Oct 2016 12:19:59 -0500	[thread overview]
Message-ID: <CAOSMAusn7mg-Ss846BBZmC=j4mU3L=1duX=2zgc9UP=YBORnsQ@mail.gmail.com> (raw)
In-Reply-To: <CAOSMAutbPNXKy_GVHDWiJv8=LRDnMPNBrsN1RgwYGVL4gJTwmg@mail.gmail.com>

Also, inspecting bash code, this seems to be code to figure out if the
file was changed from a non-regular file to a regular file between the
stat and the open, so I'd say it's indeed a bug, but the problem is
not the &&, but testing the wrong return code.

From bash redir.c

 631   /* OK, the open succeeded, but the file may have been changed from a
 632      non-regular file to a regular file between the stat and the open.
 633      We are assuming that the O_EXCL open handles the case where FILENAME
 634      did not exist and is symlinked to an existing file between the stat
 635      and open. */
 637   /* If we can open it and fstat the file descriptor, and neither check
 638      revealed that it was a regular file, and the file has not
been replaced,
 639      return the file descriptor. */
 640   if ((fstat (fd, &finfo2) == 0) && (S_ISREG (finfo2.st_mode) == 0) &&
 641       r == 0 && (S_ISREG (finfo.st_mode) == 0) &&
 642       same_file (filename, filename, &finfo, &finfo2))
 643     return fd;
 645   /* The file has been replaced.  badness. */
 646   close (fd);
 647   errno = EEXIST;
 648   return (NOCLOBBER_REDIRECT);

  reply	other threads:[~2016-10-25 17:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-25 15:33 Bug? "fstat64(f, &sb) < 0 && S_ISREG(sb.st_mode)" Denys Vlasenko
2016-10-25 17:13 ` Eduardo Bustamante
2016-10-25 17:19   ` Eduardo Bustamante [this message]
2016-10-26 21:43   ` Jilles Tjoelker
2016-10-27  0:35     ` Eduardo Bustamante

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOSMAusn7mg-Ss846BBZmC=j4mU3L=1duX=2zgc9UP=YBORnsQ@mail.gmail.com' \
    --to=dualbus@gmail.com \
    --cc=dash@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=vda.linux@googlemail.com \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).