# problem with http clone/pull

6 messages from 2006-09-12 to 2006-09-13. Participants: Paul Mackerras, Junio C Hamano.
Thread: https://gitlist.dev/t/5546

## Paul Mackerras, 2006-09-12 23:23

Subject: problem with http clone/pull
Message-ID: <17671.16741.995661.664789@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/17671.16741.995661.664789%40cargo.ozlabs.ibm.com

```
Junio,

Users are having problems doing clones or pulls of my powerpc.git tree
on kernel.org with version 1.4.2 of git.  Apparently earlier versions
work OK.

When I do:

git clone http://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git

it produces the following output:

Getting alternates list for http://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/
Also look at http://git.kernel.or
error: Couldn't resolve host 'git.kernel.orobjects' (curl_result = 6, http_code = 0, sha1 = c336923b668fdcf0312efbec3b44895d713f4d81)
Getting pack list for http://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/
Getting pack list for http://git.kernel.or
error: Couldn't resolve host 'git.kernel.or'
error: Unable to find c336923b668fdcf0312efbec3b44895d713f4d81 under http://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/
Cannot obtain needed none c336923b668fdcf0312efbec3b44895d713f4d81
while processing commit 0000000000000000000000000000000000000000.

Now, this repository has a objects/info/alternates file that contains
the single line:

/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/objects

I also have a hooks/post-update with execute permission, that does
exec git-update-server-info.

Is there anything obviously wrong in how I have set this up, or is it
a new bug in git 1.4.2?

Thanks,
Paul.

```

## Junio C Hamano, 2006-09-12 23:43

Subject: Re: problem with http clone/pull
Message-ID: <7vodtkejm9.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vodtkejm9.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <17671.16741.995661.664789@cargo.ozlabs.ibm.com>

```
Paul Mackerras <paulus@samba.org> writes:

> Getting alternates list for http://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/
> Also look at http://git.kernel.or
> error: Couldn't resolve host 'git.kernel.orobjects' (curl_result = 6, http_code = 0, sha1 = c336923b668fdcf0312efbec3b44895d713f4d81)
> Getting pack list for http://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc.git/
> Getting pack list for http://git.kernel.or

I've seen this "last character of hostname dropped" symptom
mentioned on the #git channel long time ago, but I do not
remember if somebody figured out what the problem was.  I know
that nobody did a patch to specifically fix it.

Among the changes since v1.3.0 that touches http-fetch.c the
only thing I can see that touches anything related to alternates
handling is this one, but I do not see anything obviously wrong
with it X-<.

commit bfbd0bb6ecbbbf75a5caaff6afaf5a6af8fa518e
Date:   Sun Jun 11 14:03:28 2006 +0200

    Implement safe_strncpy() as strlcpy() and use it more.
    
diff --git a/http-fetch.c b/http-fetch.c
index d3602b7..da1a7f5 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -584,10 +584,8 @@ static void process_alternates_response(
 			// skip 'objects' at end
 			if (okay) {
 				target = xmalloc(serverlen + posn - i - 6);
-				strncpy(target, base, serverlen);
-				strncpy(target + serverlen, data + i,
-					posn - i - 7);
-				target[serverlen + posn - i - 7] = '\0';
+				safe_strncpy(target, base, serverlen);
+				safe_strncpy(target + serverlen, data + i, posn - i - 6);
 				if (get_verbosely)
 					fprintf(stderr,
 						"Also look at %s\n", target);

```

## Junio C Hamano, 2006-09-13 00:06

Subject: Re: problem with http clone/pull
Message-ID: <7v7j08eikw.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v7j08eikw.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <7vodtkejm9.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano <junkio@cox.net> writes:

> I've seen this "last character of hostname dropped" symptom
> mentioned on the #git channel long time ago, but I do not
> remember if somebody figured out what the problem was.  I know
> that nobody did a patch to specifically fix it.

Perhaps this would fix it?

I am at work now and I haven't looked at the logic aruond it
too deeply (e.g. I do not know if this breaks the relative
alternate or http specific cases, nor the same or similar
breakages were there in these other cases in the original code
to begin with)

---

diff --git a/http-fetch.c b/http-fetch.c
index fac1760..d870390 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -559,7 +559,13 @@ static void process_alternates_response(
 			char *target = NULL;
 			char *path;
 			if (data[i] == '/') {
-				serverlen = strchr(base + 8, '/') - base;
+				/* This counts
+				 * http://git.host/pub/scm/linux.git
+				 * 1234567----here^
+				 * so strcpy(dst, base, serverlen) will
+				 * copy up to "...git.host/"
+				 */
+				serverlen = strchr(base + 7, '/') - base;
 				okay = 1;
 			} else if (!memcmp(data + i, "../", 3)) {
 				i += 3;
@@ -586,7 +592,7 @@ static void process_alternates_response(
 			/* skip 'objects' at end */
 			if (okay) {
 				target = xmalloc(serverlen + posn - i - 6);
-				strlcpy(target, base, serverlen);
+				memcpy(target, base, serverlen);
 				strlcpy(target + serverlen, data + i, posn - i - 6);
 				if (get_verbosely)
 					fprintf(stderr,

```

## Junio C Hamano, 2006-09-13 00:39

Subject: Re: problem with http clone/pull
Message-ID: <7vvensd2hh.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vvensd2hh.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <7v7j08eikw.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano <junkio@cox.net> writes:

> Perhaps this would fix it?
>
> I am at work now and I haven't looked at the logic aruond it
> too deeply (e.g. I do not know if this breaks the relative
> alternate or http specific cases, nor the same or similar
> breakages were there in these other cases in the original code
> to begin with)

Side note:

> diff --git a/http-fetch.c b/http-fetch.c
> index fac1760..d870390 100644
> --- a/http-fetch.c
> +++ b/http-fetch.c
> @@ -559,7 +559,13 @@ static void process_alternates_response(
>  			char *target = NULL;
>  			char *path;
>  			if (data[i] == '/') {
> -				serverlen = strchr(base + 8, '/') - base;
> +				/* This counts
> +				 * http://git.host/pub/scm/linux.git
> +				 * 1234567----here^
> +				 * so strcpy(dst, base, serverlen) will
> +				 * copy up to "...git.host/"
> +				 */
> +				serverlen = strchr(base + 7, '/') - base;
>  				okay = 1;
>  			} else if (!memcmp(data + i, "../", 3)) {
>  				i += 3;

The change between 7 and 8 does not really matter, because the
hostname cannot be empty, and 8 was masking the breakage of this
code; it was (perhaps deliberately) being sloppy to allow us to
also skip over "protocol://" part for https:// case.  Call it
subtle if you want ;-).

I think the right thing for this part to do would be something
like this:

diff --git a/http-fetch.c b/http-fetch.c
index fac1760..c7545f2 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -559,8 +559,18 @@ static void process_alternates_response(
 			char *target = NULL;
 			char *path;
 			if (data[i] == '/') {
-				serverlen = strchr(base + 8, '/') - base;
-				okay = 1;
+				/* This counts
+				 * http://git.host/pub/scm/linux.git
+				 * -----------here^
+				 * so memcpy(dst, base, serverlen) will
+				 * copy up to "...git.host".
+				 */
+				const char *colon_ss = strstr(base,"://");
+				if (colon_ss) {
+					serverlen = (strchr(colon_ss + 3, '/')
+						     - base);
+					okay = 1;
+				}
 			} else if (!memcmp(data + i, "../", 3)) {
 				i += 3;
 				serverlen = strlen(base);
@@ -583,11 +593,13 @@ static void process_alternates_response(
 					okay = 1;
 				}
 			}
-			/* skip 'objects' at end */
+			/* skip "objects\n" at end */
 			if (okay) {
 				target = xmalloc(serverlen + posn - i - 6);
-				strlcpy(target, base, serverlen);
-				strlcpy(target + serverlen, data + i, posn - i - 6);
+				memcpy(target, base, serverlen);
+				memcpy(target + serverlen, data + i,
+				       posn - i - 7);
+				target[serverlen + posn - i - 7] = 0;
 				if (get_verbosely)
 					fprintf(stderr,
 						"Also look at %s\n", target);

```

## Paul Mackerras, 2006-09-13 01:08

Subject: Re: problem with http clone/pull
Message-ID: <17671.23044.481280.965798@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/17671.23044.481280.965798%40cargo.ozlabs.ibm.com
In-Reply-To: <7v7j08eikw.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano writes:

> Perhaps this would fix it?

Yes, it works with that patch.  Thanks.

Paul.

```

## Junio C Hamano, 2006-09-13 19:03

Subject: Re: problem with http clone/pull
Message-ID: <7v7j07a8sf.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v7j07a8sf.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <17671.23044.481280.965798@cargo.ozlabs.ibm.com>

```
I'll do 1.4.2.1 with a fix for this and push it out hopefully
today.

```
