git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Habouzit <madcoder@debian.org>
To: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] git-sh-setup: fix parseopt `eval`.
Date: Thu, 08 Nov 2007 10:35:15 +0100	[thread overview]
Message-ID: <20071108093515.GC7391@artemis.corp> (raw)
In-Reply-To: <20071108091402.GA7391@artemis.corp>

[-- Attachment #1: Type: text/plain, Size: 2906 bytes --]

On Thu, Nov 08, 2007 at 09:14:02AM +0000, Pierre Habouzit wrote:
> On Thu, Nov 08, 2007 at 07:09:29AM +0000, Junio C Hamano wrote:
> > The 'automagic parseopt' support corrupted non option parameters
> > that had IFS characters in them.  The worst case can be seen
> > when it has a non option parameter like this:
> > 
> > 	$1=" * some string   blech"
> > 
> > Signed-off-by: Junio C Hamano <gitster@pobox.com>
> 
> > -	parseopt_extra=
> > -	[ -n "$OPTIONS_KEEPDASHDASH" ] &&
> > -		parseopt_extra="$parseopt_extra --keep-dashdash"
> > +	[ -n "$OPTIONS_KEEPDASHDASH" ] && parseopt_extra="--keep-dashdash"
> 
>   oh and this part is wrong because you're affected by $parseopt_extra
> environment poisonning. And you have to fix git-clone.sh that uses
> git-rev-parse --parsopt directly with the same call too (as it doesn't
> use git-sh-setup).

  Here is a patch that should fix all those issues at once, replace
yours.  I tested it with this minimal test:

    $ cat parseopt.sh
    #!/bin/sh

    OPTIONS_KEEPDASHDASH=
    OPTIONS_SPEC="\
    foo
    --
    "
    . git-sh-setup
    for i in "$@"; do echo "$i"; done
    $ ./parseopt.sh " * hahahah	bleh"
    --
     * hahahah     bleh
    $ ./parseopt.sh -asd " * hahahah     bleh"
    error: unknown switch `a'
    usage: foo


    $ echo $?
    129

which fix your bug, and still behaves as advertised.


From 3c2095533094ff6d82272dc36d9f576b0e81d135 Mon Sep 17 00:00:00 2001
From: Pierre Habouzit <madcoder@debian.org>
Date: Thu, 8 Nov 2007 10:32:11 +0100
Subject: [PATCH] Prevent eval of $(git-rev-parse --parseopt) output to be shell-expansed.

Thanks to Junio for having spotted this.
Use the preferred $(...) form rather than ``

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 git-clone.sh    |    2 +-
 git-sh-setup.sh |    8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index f216f03..24ad179 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -36,7 +36,7 @@ usage() {
 	exec "$0" -h
 }
 
-eval `echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?`
+eval "$(echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
 
 get_repo_base() {
 	(
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index e1cf885..5aa62dd 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -23,9 +23,13 @@ if test -n "$OPTIONS_SPEC"; then
 
 	parseopt_extra=
 	[ -n "$OPTIONS_KEEPDASHDASH" ] &&
-		parseopt_extra="$parseopt_extra --keep-dashdash"
+		parseopt_extra="--keep-dashdash"
 
-	eval `echo "$OPTIONS_SPEC" | git rev-parse --parseopt $parseopt_extra -- "$@" || echo exit $?`
+	eval "$(
+		echo "$OPTIONS_SPEC" |
+			git rev-parse --parseopt $parseopt_extra -- "$@" ||
+		echo exit $?
+	)"
 else
 	usage() {
 		die "Usage: $0 $USAGE"
-- 
1.5.3.5.1598.gdef4e-dirty


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2007-11-08  9:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-08  7:09 [PATCH] git-sh-setup: fix parseopt `eval` Junio C Hamano
2007-11-08  8:15 ` Pierre Habouzit
2007-11-08  9:14 ` Pierre Habouzit
2007-11-08  9:35   ` Pierre Habouzit [this message]

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

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

  git send-email \
    --in-reply-to=20071108093515.GC7391@artemis.corp \
    --to=madcoder@debian.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
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 NNTP newsgroup(s).