git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: Fix "getaddrinfo()" buglet
Date: Tue, 27 Mar 2007 09:50:20 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0703270938380.6730@woody.linux-foundation.org> (raw)


At least in Linux glibc, "getaddrinfo()" has a very irritating feature (or 
bug, who knows..).

Namely if you pass it in an empty string for the service name, it will 
happily and quietly consider it identical to a NULL port pointer, and 
return port number zero and no errors. Which obviously will not work.

Maybe that's what it's really expected to do, although the man-page for 
getaddrinfo() certainly implies that it's a bug.

So when somebody passes me a "please pull" request pointing to something 
like the following

	git://git.kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb.git

(note the extraneous colon at the end of the host name), git would happily 
try to connect to port 0, which would generally just cause the remote to 
not even answer, and the "connect()" will take a long time to time out.

So to work around the glibc feature/bug, just notice this empty port case 
automatically. Also, add the port information to the error information 
when it fails to look up (maybe it's the host-name that fails, maybe it's 
the port-name - we should print out both).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

 connect.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/connect.c b/connect.c
index 5048653..da89c9c 100644
--- a/connect.c
+++ b/connect.c
@@ -417,6 +417,8 @@ static int git_tcp_connect_sock(char *host)
 	if (colon) {
 		*colon = 0;
 		port = colon + 1;
+		if (!*port)
+			port = "<none>";
 	}
 
 	memset(&hints, 0, sizeof(hints));
@@ -425,7 +427,7 @@ static int git_tcp_connect_sock(char *host)
 
 	gai = getaddrinfo(host, port, &hints, &ai);
 	if (gai)
-		die("Unable to look up %s (%s)", host, gai_strerror(gai));
+		die("Unable to look up %s (port %s) (%s)", host, port, gai_strerror(gai));
 
 	for (ai0 = ai; ai; ai = ai->ai_next) {
 		sockfd = socket(ai->ai_family,

                 reply	other threads:[~2007-03-27 16:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=Pine.LNX.4.64.0703270938380.6730@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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).