git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] run-command: don't try to execute directories

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 2, 2012, 19:59 UTC
Message-ID
<7vd3107igx.fsf@alter.siamese.dyndns.org>
In-Reply-To
<87bogkisas.fsf@centaur.cmartin.tk>
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?

Show 25 quoted lines
>
> ---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)
Previous: Carlos Martín NietoNext: Jeff King
Message 4 of 5 in “run-command: don't try to execute directories”
  1. run-command: don't try to execute directoriesCarlos Martín Nieto, Oct 2, 2012
  2. Junio C HamanoOct 2, 2012
  3. Carlos Martín NietoOct 2, 2012
  4. Junio C HamanoOct 2, 2012
  5. Jeff KingOct 2, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.