On 10/10/21 20:24, Dmitry Goncharov via Bug reports for the GNU Bourne
Again SHell wrote:
> On Sun, Oct 10, 2021 at 7:52 PM Ángel <an...@16bits.net> wrote:
>> Looking at the code, it doesn't even need an extra stat(), it already
>> knows the file exists
> 
> Attempts to know ahead of time or check afterwards that the file
> exists are subject to a race condition.


Immediately above the patch diff you are responding to, is:



#if defined (HAVE_HASH_BANG_EXEC)
          READ_SAMPLE_BUF (command, sample, sample_len);
          if (sample_len > 0)
            sample[sample_len - 1] = '\0';
          if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
            {
              char *interp;
              int ilen;

              interp = getinterp (sample, sample_len, (int *)NULL);
              ilen = strlen (interp);
              errno = i;
              if (interp[ilen - 1] == '\r')
                {
                  interp = xrealloc (interp, ilen + 2);
                  interp[ilen - 1] = '^';
                  interp[ilen] = 'M';
                  interp[ilen + 1] = '\0';
                }
              sys_error (_("%s: %s: bad interpreter"), command, interp ? interp
: "");
              FREE (interp);
              return (EX_NOEXEC);
            }
#endif



So I wonder, if bash already in this exact case attempts to open() the
file and read() it to look for a shebang, what's the harm in assuming
(or checking) that it exists in this patch?



-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

  • Misleading... Andrea Monaco
    • Re: M... Alex fxmbsw7 Ratchev
    • Re: M... Chet Ramey
      • R... Ilkka Virta
        • ... Dennis Williamson
        • ... Chet Ramey
          • ... Alex fxmbsw7 Ratchev
            • ... Ángel
              • ... Dmitry Goncharov via Bug reports for the GNU Bourne Again SHell
                • ... Eli Schwartz
                • ... Dmitry Goncharov via Bug reports for the GNU Bourne Again SHell
                • ... Robert Elz
                • ... Chet Ramey
                • ... Robert Elz
                • ... Alex fxmbsw7 Ratchev
                • ... Ángel
                • ... Eli Schwartz
    • Re: M... Andrea Monaco
      • R... Alex fxmbsw7 Ratchev

Reply via email to