git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Sebastian Schuberth <sschuberth@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>,
	Lukas Fleischer <lfleischer@lfos.de>,
	Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 0/2] fix clone guess_dir_name regression in v2.4.8
Date: Wed, 5 Aug 2015 04:35:26 -0400	[thread overview]
Message-ID: <20150805083526.GA22325@sigill.intra.peff.net> (raw)
In-Reply-To: <20150804224246.GA29051@sigill.intra.peff.net>

On Tue, Aug 04, 2015 at 06:42:46PM -0400, Jeff King wrote:

> > I did not intend this change in behavior, and I can confirm that
> > reverting my patch restores the original behavior. Thanks for bringing
> > this to my attention, I'll work on a patch.
> 
> I think this regression is in v2.4.8, as well. We should be able to use
> a running "len" instead of the "end" pointer in the earlier part, and
> then use strip_suffix_mem later (to strip from our already-reduced
> length, rather than the full NUL-terminated string). Like this:

Looks like "git clone --bare host:foo/.git" is broken, too. I've added
some tests to cover the recently broken cases, as well as some obvious
normal cases (which the patch I sent earlier break!). And as a bonus, we
can easily cover Patrick's root-repo problems (so people will actually
run the tests, unlike the stuff in t1509. :) ).

> @@ -167,14 +166,14 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
>  	 * the form  "remote.example.com:foo.git", i.e. no slash
>  	 * in the directory part.
>  	 */
> -	start = end;
> +	start = repo + len;
>  	while (repo < start && !is_dir_sep(start[-1]) && start[-1] != ':')
>  		start--;
>  
>  	/*
>  	 * Strip .{bundle,git}.
>  	 */
> -	strip_suffix(start, is_bundle ? ".bundle" : ".git" , &len);
> +	strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git");

This is crap, of course. Our "len" variable is computed from the start
of "repo", of which "start" is a subset. So we are indexing way out of
bounds here.

As it turns out, this actually makes things simpler. We can stop using
"len" entirely in the early part, and leave it as-is with pointer math
(the patch I sent earlier did not really make anything simpler, anyway).
And then we can just compute the length of "start" here, minus
everything we've stripped off the end (i.e., "len = end - start").

Here are the patches.

  [1/2]: clone: add tests for output directory
  [2/2]: clone: use computed length in guess_dir_name

-Peff

  parent reply	other threads:[~2015-08-05  8:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09 15:33 [PATCH] clone: Make use of the strip_suffix() helper method Sebastian Schuberth
2015-07-09 17:00 ` Jeff King
2015-07-09 17:16   ` Sebastian Schuberth
2015-07-09 17:23     ` [PATCH v2] clone: Simplify string handling in guess_dir_name() Sebastian Schuberth
2015-07-09 18:05       ` Junio C Hamano
2015-07-09 18:16         ` Sebastian Schuberth
2015-07-09 18:20           ` [PATCH v3] " Sebastian Schuberth
2015-07-09 18:24           ` [PATCH v4] clone: simplify " Sebastian Schuberth
2015-07-09 21:21             ` Junio C Hamano
2015-07-09 21:23               ` Sebastian Schuberth
2015-08-04  4:34             ` Lukas Fleischer
2015-08-04  7:31               ` Sebastian Schuberth
2015-08-04 22:42                 ` Jeff King
2015-08-05  6:08                   ` Patrick Steinhardt
2015-08-05  8:41                     ` Jeff King
2015-08-05  9:06                       ` Patrick Steinhardt
2015-08-05  9:09                         ` Jeff King
2015-08-05  8:35                   ` Jeff King [this message]
2015-08-05  8:36                     ` [PATCH 1/2] clone: add tests for output directory Jeff King
2015-08-05  8:39                     ` [PATCH 2/2] clone: use computed length in guess_dir_name Jeff King
2015-08-05  8:49                       ` Sebastian Schuberth
2015-08-05 17:19                     ` [PATCH 0/2] fix clone guess_dir_name regression in v2.4.8 Junio C Hamano
2015-08-05 21:04                       ` Jeff King
2015-07-09 18:40           ` [PATCH v2] clone: Simplify string handling in guess_dir_name() Junio C Hamano

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=20150805083526.GA22325@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=lfleischer@lfos.de \
    --cc=ps@pks.im \
    --cc=sschuberth@gmail.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).