@matheusbsbs / matheus-bagliano / commits / 608d48b220
Fork 0

Fix "getaddrinfo()" buglet

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Mar 27, 2007 at 09:50 UTC 608d48b2207a6152839a9762c7a66f217bceb440
1 file changed +3 -1
connect.c
+3 -1
@@ -417,6 +417,8 @@ static int git_tcp_connect_sock(char *host)
417 if (colon) {
418 *colon = 0;
419 port = colon + 1;
420 + if (!*port)
421 + port = "<none>";
422 }
423
424 memset(&hints, 0, sizeof(hints));
@@ -425,7 +427,7 @@ static int git_tcp_connect_sock(char *host)
427
428 gai = getaddrinfo(host, port, &hints, &ai);
429 if (gai)
428 - die("Unable to look up %s (%s)", host, gai_strerror(gai));
430 + die("Unable to look up %s (port %s) (%s)", host, port, gai_strerror(gai));
431
432 for (ai0 = ai; ai; ai = ai->ai_next) {
433 sockfd = socket(ai->ai_family,