bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Misleading error when attempting to run foreign executable


From: Eli Schwartz
Subject: Re: Misleading error when attempting to run foreign executable
Date: Sun, 10 Oct 2021 21:09:53 -0400

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 <angel@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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]