{"thread":{"id":"37656","subject":"[PATCH 1/3] daemon: handle gethostbyname() error","startedAt":"2014-10-01T10:16:17Z","lastAt":"2014-10-01T20:35:48Z","messageCount":4,"participants":["René Scharfe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"250061","messageId":"542BD471.3000308@web.de","threadId":"37656","inReplyTo":null,"subject":"[PATCH 1/3] daemon: handle gethostbyname() error","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-10-01T10:16:17Z","receivedAt":"2014-10-01T10:16:17Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"If the user-supplied hostname can't be found then we should not use it.\nWe already avoid doing that in the non-NO_IPV6 case by checking if the\nreturn value of getaddrinfo() is zero (success).  Do the same in the\nNO_IPV6 case and make sure the return value of gethostbyname() isn't\nNULL before dereferencing this pointer.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\nMost lines are just re-indented, not actually changed.\n\n daemon.c | 27 ++++++++++++++-------------\n 1 file changed, 14 insertions(+), 13 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex 4dcfff9..a6f467e 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -553,20 +553,21 @@ static void parse_host_arg(char *extra_args, int buflen)\n \t\tstatic char addrbuf[HOST_NAME_MAX + 1];\n \n \t\thent = gethostbyname(hostname);\n+\t\tif (hent) {\n+\t\t\tap = hent->h_addr_list;\n+\t\t\tmemset(&sa, 0, sizeof sa);\n+\t\t\tsa.sin_family = hent->h_addrtype;\n+\t\t\tsa.sin_port = htons(0);\n+\t\t\tmemcpy(&sa.sin_addr, *ap, hent->h_length);\n+\n+\t\t\tinet_ntop(hent->h_addrtype, &sa.sin_addr,\n+\t\t\t\t  addrbuf, sizeof(addrbuf));\n \n-\t\tap = hent->h_addr_list;\n-\t\tmemset(&sa, 0, sizeof sa);\n-\t\tsa.sin_family = hent->h_addrtype;\n-\t\tsa.sin_port = htons(0);\n-\t\tmemcpy(&sa.sin_addr, *ap, hent->h_length);\n-\n-\t\tinet_ntop(hent->h_addrtype, &sa.sin_addr,\n-\t\t\t  addrbuf, sizeof(addrbuf));\n-\n-\t\tfree(canon_hostname);\n-\t\tcanon_hostname = xstrdup(hent->h_name);\n-\t\tfree(ip_address);\n-\t\tip_address = xstrdup(addrbuf);\n+\t\t\tfree(canon_hostname);\n+\t\t\tcanon_hostname = xstrdup(hent->h_name);\n+\t\t\tfree(ip_address);\n+\t\t\tip_address = xstrdup(addrbuf);\n+\t\t}\n #endif\n \t}\n }\n-- \n2.1.2\n"},{"id":"250062","messageId":"542BD4E7.7030401@web.de","threadId":"37656","inReplyTo":"542BD471.3000308@web.de","subject":"[PATCH 2/3] daemon: fix error message after bind()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-10-01T10:18:15Z","receivedAt":"2014-10-01T10:18:15Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Signed-off-by: Rene Scharfe <l.s.r@web.de>\n---\n daemon.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex a6f467e..090f6a4 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -924,7 +924,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis\n \t}\n \n \tif ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {\n-\t\tlogerror(\"Could not listen to %s: %s\",\n+\t\tlogerror(\"Could not bind to %s: %s\",\n \t\t\t ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),\n \t\t\t strerror(errno));\n \t\tclose(sockfd);\n-- \n2.1.2\n"},{"id":"250063","messageId":"542BD5C5.7050604@web.de","threadId":"37656","inReplyTo":"542BD4E7.7030401@web.de","subject":"[PATCH 3/3] daemon: remove write-only variable maxfd","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-10-01T10:21:57Z","receivedAt":"2014-10-01T10:21:57Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"It became unused when 6573faff (NO_IPV6 support for git daemon) replaced\nselect() with poll().\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n daemon.c | 4 ----\n 1 file changed, 4 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex 090f6a4..54a03bd 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -815,7 +815,6 @@ static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)\n static int setup_named_sock(char *listen_addr, int listen_port, struct socketlist *socklist)\n {\n \tint socknum = 0;\n-\tint maxfd = -1;\n \tchar pbuf[NI_MAXSERV];\n \tstruct addrinfo hints, *ai0, *ai;\n \tint gai;\n@@ -883,9 +882,6 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis\n \t\tALLOC_GROW(socklist->list, socklist->nr + 1, socklist->alloc);\n \t\tsocklist->list[socklist->nr++] = sockfd;\n \t\tsocknum++;\n-\n-\t\tif (maxfd < sockfd)\n-\t\t\tmaxfd = sockfd;\n \t}\n \n \tfreeaddrinfo(ai0);\n-- \n2.1.2\n"},{"id":"250127","messageId":"xmqqlhozply3.fsf@gitster.dls.corp.google.com","threadId":"37656","inReplyTo":"542BD471.3000308@web.de","subject":"Re: [PATCH 1/3] daemon: handle gethostbyname() error","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-10-01T20:35:48Z","receivedAt":"2014-10-01T20:35:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"All three look trivially correct.  Thanks.\n"}]}