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

Re: [PATCH v2] git submodule foreach: Skip eval for more than one argument

From
Johan Herland <johan@herland.net>
Date
Sep 27, 2013, 10:47 UTC
Message-ID
<CALKQrgfT1ijSx7hmtFRE7=Wm1LCtVH4ceeSQfuFF7Qswa+wRpg@mail.gmail.com>
In-Reply-To
<alpine.DEB.2.00.1309270606290.20647@dr-wily.mit.edu>
On Fri, Sep 27, 2013 at 12:23 PM, Anders Kaseorg <andersk@mit.edu> wrote:
Show 15 quoted lines
> ‘eval "$@"’ created an extra layer of shell interpretation, which was
> probably not expected by a user who passed multiple arguments to git
> submodule foreach:
>
> $ git grep "'"
> [searches for single quotes]
> $ git submodule foreach git grep "'"
> Entering '[submodule]'
> /usr/lib/git-core/git-submodule: 1: eval: Syntax error: Unterminated quoted string
> Stopping at '[submodule]'; script returned non-zero status.
>
> To fix this, if the user passed more than one argument, just execute
> "$@" directly instead of passing it to eval.
>
> Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Acked-by: Johan Herland <johan@herland.net>
Show 25 quoted lines
> On Fri, 27 Sep 2013, Johan Herland wrote:
>> 2. If we are unlucky there might be existing users that work around the
>> existing behavior by adding an extra level of quoting (i.e. doing the
>> equivalent of git submodule foreach git grep "\'" in your example
>> above). Will their workaround break as a result of your change? Is that
>> acceptable?
>
> Anyone adding an extra level of quoting ought to realize that they should
> be passing a single argument to submodule foreach, so that the reason for
> the extra quoting is clear:
>   git submodule foreach "git grep \'"
> will not break.  If someone is actually doing
>   git submodule foreach git grep "\'"
> then this will change in behavior.  I think this change is important.
>
> (One could even imagine someone feeding untrusted input to
>   git submodule foreach git grep "$variable"
> which, without my patch, results in a nonobvious shell code injection
> vulnerability.)
>
> I considered an alternative fix where the first argument is always
> shell-evaulated and any others are not (i.e. cmd=$1 && shift && eval
> "$cmd \"\$@\""), which is potentially more useful in case the command
> needs to use $path.  But that may be too confusing, and this way has some
> precedent (e.g. perl’s system()).
Ok. I have nothing to add.
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Previous: Anders KaseorgNext: Matthijs Kooijman
Message 4 of 9 in “git submodule foreach: Skip eval for more than one argument”
  1. git submodule foreach: Skip eval for more than one argumentAnders Kaseorg, Sep 26, 2013
  2. Johan HerlandSep 27, 2013
  3. git submodule foreach: Skip eval for more than one argumentAnders Kaseorg, Sep 27, 2013
  4. Johan HerlandSep 27, 2013
  5. Matthijs KooijmanMar 4, 2014
  6. Johan HerlandMar 4, 2014
  7. Matthijs KooijmanMar 4, 2014
  8. Johan HerlandMar 4, 2014
  9. Matthijs KooijmanMar 4, 2014

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.