git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: John Keeping <john@keeping.me.uk>
To: Guillaume Gelin <contact@ramnes.eu>, git@vger.kernel.org
Subject: Re: git 1.9.0 segfault
Date: Sat, 8 Mar 2014 18:12:18 +0000	[thread overview]
Message-ID: <20140308181218.GG18371@serenity.lan> (raw)
In-Reply-To: <20140308164651.GA32213@vauxhall.crustytoothpaste.net>

On Sat, Mar 08, 2014 at 04:46:51PM +0000, brian m. carlson wrote:
> On Sat, Mar 08, 2014 at 04:23:43PM +0000, Guillaume Gelin wrote:
> > Hi,
> >
> > http://pastebin.com/Np7L54ar
> We're failing to rename because we got an EFAULT, and then we try to
> print the failing filename, and we get a segfault right here:
> 
> 			if (rename(src, dst) < 0 && !ignore_errors)
> 				die_errno (_("renaming '%s' failed"), src);
> 
> I don't know yet if dst is also bad, but clearly src is.  I'm looking
> into it.

The problem seems to be that we change argc when we append nested
directories to the list and then continue looping over 'source' which
has been realloc'd to be larger.  But we do not realloc
submodule_gitfile at the same time so we start writing beyond the end of
the submodule_gitfile array.

The particular behaviour of glibc's malloc happens to mean (at least on
my system) that this starts overwriting 'src'.

This fixes it for me:

-- >8 --
diff --git a/builtin/mv.c b/builtin/mv.c
index 7e26eb5..23f119a 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -180,6 +180,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 						modes = xrealloc(modes,
 								(argc + last - first)
 								* sizeof(enum update_mode));
+						submodule_gitfile = xrealloc(submodule_gitfile,
+								(argc + last - first)
+								* sizeof(char *));
 					}
 
 					dst = add_slash(dst);

  reply	other threads:[~2014-03-08 18:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-08 16:23 git 1.9.0 segfault Guillaume Gelin
2014-03-08 16:46 ` brian m. carlson
2014-03-08 18:12   ` John Keeping [this message]
2014-03-08 18:35     ` [PATCH] builtin/mv: fix out of bounds write John Keeping
2014-03-08 19:15       ` brian m. carlson
2014-03-08 19:29         ` [PATCH v2] " John Keeping
2014-03-08 19:21       ` [PATCH] mv: prevent mismatched data when ignoring errors brian m. carlson
2014-03-11  1:56         ` Jeff King
2014-03-11  2:00           ` brian m. carlson
2014-03-11 21:45         ` Junio C Hamano
2014-03-12 23:21           ` brian m. carlson
2014-03-15 16:05         ` Thomas Rast
2014-03-16  2:00           ` Jeff King
2014-03-16 21:20             ` Junio C Hamano
2014-03-17  6:33               ` Junio C Hamano
2014-03-17 15:07                 ` Michael Haggerty
2014-03-17 19:06                   ` Eric Sunshine
2014-03-17 22:04                     ` Jeff King
2014-03-18 22:31                   ` Junio C Hamano
2014-03-15 18:56         ` [PATCH v2] " brian m. carlson
2014-03-16  2:00           ` Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20140308181218.GG18371@serenity.lan \
    --to=john@keeping.me.uk \
    --cc=contact@ramnes.eu \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).