# [PATCH] apply: fix access to an uninitialized mode variable, found by valgrind

5 messages from 2009-02-04 to 2009-02-04. Participants: Johannes Schindelin, Junio C Hamano, Don Zickus, Jeff King.
Thread: https://gitlist.dev/t/17544

## Johannes Schindelin, 2009-02-04 01:50

Subject: [PATCH] apply: fix access to an uninitialized mode variable, found by valgrind
Message-ID: <alpine.DEB.1.00.0902040249030.9822@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0902040249030.9822%40pacific.mpi-cbg.de
In-Reply-To: <cover.1233712140u.git.johannes.schindelin@gmx.de>

```
When 'tpatch' was initialized successfully, st_mode was already taken
from the previous diff.  We should not try to override it with data
from an lstat() that was never called.

This is a companion patch to 7a07841(git-apply: handle a patch that
touches the same path more than once better).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-apply.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-apply.c b/builtin-apply.c
index 1e7f917..f312798 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -2441,7 +2441,7 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s
 		return error("%s: %s", old_name, strerror(errno));
 	}
 
-	if (!cached)
+	if (!cached && !tpatch)
 		st_mode = ce_mode_from_stat(*ce, st->st_mode);
 
 	if (patch->is_new < 0)
-- 
1.6.1.2.582.g3fdd5

```

## Junio C Hamano, 2009-02-04 07:46

Subject: Re: [PATCH] apply: fix access to an uninitialized mode variable, found by valgrind
Message-ID: <7vljsm4pb1.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vljsm4pb1.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <alpine.DEB.1.00.0902040249030.9822@pacific.mpi-cbg.de>

```
Looks correct; thanks.

```

## Don Zickus, 2009-02-04 14:36

Subject: Re: [PATCH] apply: fix access to an uninitialized mode variable, found by valgrind
Message-ID: <20090204143634.GY3827@redhat.com>
URL: https://gitlist.dev/e/20090204143634.GY3827%40redhat.com
In-Reply-To: <alpine.DEB.1.00.0902040249030.9822@pacific.mpi-cbg.de>

```
On Wed, Feb 04, 2009 at 02:50:15AM +0100, Johannes Schindelin wrote:
> When 'tpatch' was initialized successfully, st_mode was already taken
> from the previous diff.  We should not try to override it with data
> from an lstat() that was never called.

heh, oops.  thanks.

Acked-by:  Don Zickus <dzickus@redhat.com>

```

## Jeff King, 2009-02-04 15:31

Subject: Re: [PATCH] apply: fix access to an uninitialized mode variable, found by valgrind
Message-ID: <20090204153150.GC6896@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20090204153150.GC6896%40sigill.intra.peff.net
In-Reply-To: <alpine.DEB.1.00.0902040249030.9822@pacific.mpi-cbg.de>

```
On Wed, Feb 04, 2009 at 02:50:15AM +0100, Johannes Schindelin wrote:

> When 'tpatch' was initialized successfully, st_mode was already taken
> from the previous diff.  We should not try to override it with data
> from an lstat() that was never called.

Yay. Valgrind For The Win, as the kids are saying these days.

Was this being triggered by t4121 and t4127? If so, then I think it
solves the mystery valgrind errors I reported in the last paragraph
here:

  http://article.gmane.org/gmane.comp.version-control.git/98898

-Peff

```

## Johannes Schindelin, 2009-02-04 16:44

Subject: Re: [PATCH] apply: fix access to an uninitialized mode variable, found by valgrind
Message-ID: <alpine.DEB.1.00.0902041743530.22763@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0902041743530.22763%40intel-tinevez-2-302
In-Reply-To: <20090204153150.GC6896@sigill.intra.peff.net>

```
Hi,

On Wed, 4 Feb 2009, Jeff King wrote:

> On Wed, Feb 04, 2009 at 02:50:15AM +0100, Johannes Schindelin wrote:
> 
> > When 'tpatch' was initialized successfully, st_mode was already taken
> > from the previous diff.  We should not try to override it with data
> > from an lstat() that was never called.
> 
> Yay. Valgrind For The Win, as the kids are saying these days.

Yes, indeed.

> Was this being triggered by t4121 and t4127? If so, then I think it 
> solves the mystery valgrind errors I reported in the last paragraph 
> here:
> 
>   http://article.gmane.org/gmane.comp.version-control.git/98898

Yep, t4121 and t4127.  But I did not have time to follow the link.

Ciao,
Dscho

```
