git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: cmn@elego.de (Carlos Martín Nieto)
Cc: git@vger.kernel.org
Subject: Re: [PATCH] run-command: don't try to execute directories
Date: Tue, 02 Oct 2012 12:59:58 -0700	[thread overview]
Message-ID: <7vd3107igx.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <87bogkisas.fsf@centaur.cmartin.tk> ("Carlos Martín Nieto"'s message of "Tue, 02 Oct 2012 21:32:11 +0200")

cmn@elego.de (Carlos Martín Nieto) writes:

> How about something like this instead? We keep the access check and only
> do the stat call when we have found something we want to look at.

Sounds safer.

Looking at the way the stat call is indented twice, I suspect that
the variable can be defined inner scope, not at the top-level of the
function?

>
> ---8<---
>
> diff --git a/run-command.c b/run-command.c
> index 1101ef7..fb8a93c 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -85,6 +85,7 @@ static char *locate_in_PATH(const char *file)
>  {
>         const char *p = getenv("PATH");
>         struct strbuf buf = STRBUF_INIT;
> +       struct stat st;
>  
>         if (!p || !*p)
>                 return NULL;
> @@ -101,7 +102,8 @@ static char *locate_in_PATH(const char *file)
>                 }
>                 strbuf_addstr(&buf, file);
>  
> -               if (!access(buf.buf, F_OK))
> +               if (!access(buf.buf, F_OK) &&
> +                   !stat(buf.buf, &st) && !S_ISDIR(st.st_mode))
>                         return strbuf_detach(&buf, NULL);
>  
>                 if (!*end)

  reply	other threads:[~2012-10-02 20:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-02 14:46 [PATCH] run-command: don't try to execute directories Carlos Martín Nieto
2012-10-02 17:35 ` Junio C Hamano
2012-10-02 19:32   ` Carlos Martín Nieto
2012-10-02 19:59     ` Junio C Hamano [this message]
2012-10-02 21:26     ` Jeff King

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7vd3107igx.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=cmn@elego.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).