threads / discuss / 5546

problem with http clone/pull

Subject: problem with http clone/pull

## tl;dr

6 messages between Sep 12, 2006 and Sep 13, 2006.

replies: 5people: 2as markdown or json

Paul Mackerras· Sep 12, 2006, 23:23 UTC · lore
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· Sep 12, 2006, 23:43 UTC · re: Paul Mackerras · lore

Re: problem with http clone/pull

Paul Mackerras <paulus@samba.org> writes:
Show 5 quoted lines
> 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· Sep 13, 2006, 00:06 UTC · re: Junio C Hamano · lore

Re: problem with http clone/pull

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· Sep 13, 2006, 00:39 UTC · re: Junio C Hamano · lore

Re: problem with http clone/pull

Junio C Hamano <junkio@cox.net> writes:
Show 7 quoted lines
> 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:
Show 19 quoted lines
> 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);

← back to recent threads