# git shell scripts flaw wrt dirty env

3 messages from 2007-08-03 to 2007-08-06. Participants: Pierre Habouzit, Gerrit Pape, Junio C Hamano.
Thread: https://gitlist.dev/t/9369

## Pierre Habouzit, 2007-08-03 20:14

Subject: git shell scripts flaw wrt dirty env
Message-ID: <20070803201405.GB12430@artemis.corp>
URL: https://gitlist.dev/e/20070803201405.GB12430%40artemis.corp

```

  I recently had an issue with git-rebase, and actually git-am, kind of
hard to track down. After some hassle to understand what was going on,
it happened that for an idiotic reason (me trying a fancy new login
manager for X that didn't cleansed environment before staring X) made
all my env dirty. In particular it had $resume (in small letters) set to
/dev/sda5, and git-am happens to use the very same variable, without
cleansing the environment.

  I'm maybe completely out of luck, and that's the sole unsafe use of
variables in git shell scripts, but I don't think so, and maybe some
kind of failsafe could be used. A crude way is to call:

  unset `env | cut -d= -f1 | grep -v [A-Z]`

  at the beginning of every script, so that every lowercase-only
variables are unset, hence can be safely used. But it's completely
tasteless. Though, as it can really lead to _very_ odd bugs, well, I
just wanted to share the issue. For the curious, you can read on [0]
what the issue looked like for me...


  [0] http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=38;bug=435807#38

Cheers,
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

```

## Gerrit Pape, 2007-08-06 14:15

Subject: [PATCH] git-am: initialize variable $resume on startup
Message-ID: <20070806141530.10422.qmail@8bd9c2a0b9ecab.315fe32.mid.smarden.org>
URL: https://gitlist.dev/e/20070806141530.10422.qmail%408bd9c2a0b9ecab.315fe32.mid.smarden.org
In-Reply-To: <20070803201405.GB12430@artemis.corp>

```
git-am expects the variable $resume to be empty or unset, which might not
be the case if $resume is set in the user's environment.  So initialize
it to an empty value on startup.

The problem was noticed by Pierre Habouzit and reported through
 http://bugs.debian.org/435807

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 git-am.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 6cf0eee..b5ed8ca 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -103,7 +103,8 @@ It does not apply to blobs recorded in its index."
 }
 
 prec=4
-dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary= resolvemsg=
+dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
+resolvemsg= resume=
 git_apply_opt=
 
 while case "$#" in 0) break;; esac
-- 
1.5.3.GIT

```

## Junio C Hamano, 2007-08-06 23:16

Subject: Re: [PATCH] git-am: initialize variable $resume on startup
Message-ID: <7vlkco9ruf.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vlkco9ruf.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070806141530.10422.qmail@8bd9c2a0b9ecab.315fe32.mid.smarden.org>

```
Thanks.

```
