mirror of
https://github.com/git/git.git
synced 2026-06-19 15:39:47 +02:00
Merge branch 'st/daemon-sockaddr-fixes'
Correct use of sockaddr API in "git daemon". * st/daemon-sockaddr-fixes: daemon: guard NULL REMOTE_PORT in execute() logging daemon: fix IPv6 address truncation in ip2str() daemon: fix IPv6 address corruption in lookup_hostname()
This commit is contained in:
@@ -674,9 +674,20 @@ static void lookup_hostname(struct hostinfo *hi)
|
||||
|
||||
gai = getaddrinfo(hi->hostname.buf, NULL, &hints, &ai);
|
||||
if (!gai) {
|
||||
struct sockaddr_in *sin_addr = (void *)ai->ai_addr;
|
||||
void *addr;
|
||||
|
||||
inet_ntop(AF_INET, &sin_addr->sin_addr,
|
||||
if (ai->ai_family == AF_INET) {
|
||||
struct sockaddr_in *sa = (void *)ai->ai_addr;
|
||||
addr = &sa->sin_addr;
|
||||
} else if (ai->ai_family == AF_INET6) {
|
||||
struct sockaddr_in6 *sa6 = (void *)ai->ai_addr;
|
||||
addr = &sa6->sin6_addr;
|
||||
} else {
|
||||
die("unexpected address family: %d",
|
||||
ai->ai_family);
|
||||
}
|
||||
|
||||
inet_ntop(ai->ai_family, addr,
|
||||
addrbuf, sizeof(addrbuf));
|
||||
strbuf_addstr(&hi->ip_address, addrbuf);
|
||||
|
||||
@@ -742,7 +753,7 @@ static int execute(void)
|
||||
struct strvec env = STRVEC_INIT;
|
||||
|
||||
if (addr)
|
||||
loginfo("Connection from %s:%s", addr, port);
|
||||
loginfo("Connection from %s:%s", addr, port ? port : "?");
|
||||
|
||||
set_keep_alive(0);
|
||||
alarm(init_timeout ? init_timeout : timeout);
|
||||
@@ -936,7 +947,7 @@ struct socketlist {
|
||||
size_t alloc;
|
||||
};
|
||||
|
||||
static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)
|
||||
static const char *ip2str(int family, struct sockaddr *sin)
|
||||
{
|
||||
#ifdef NO_IPV6
|
||||
static char ip[INET_ADDRSTRLEN];
|
||||
@@ -947,11 +958,11 @@ static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)
|
||||
switch (family) {
|
||||
#ifndef NO_IPV6
|
||||
case AF_INET6:
|
||||
inet_ntop(family, &((struct sockaddr_in6*)sin)->sin6_addr, ip, len);
|
||||
inet_ntop(family, &((struct sockaddr_in6*)sin)->sin6_addr, ip, sizeof(ip));
|
||||
break;
|
||||
#endif
|
||||
case AF_INET:
|
||||
inet_ntop(family, &((struct sockaddr_in*)sin)->sin_addr, ip, len);
|
||||
inet_ntop(family, &((struct sockaddr_in*)sin)->sin_addr, ip, sizeof(ip));
|
||||
break;
|
||||
default:
|
||||
xsnprintf(ip, sizeof(ip), "<unknown>");
|
||||
@@ -1008,14 +1019,14 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
|
||||
|
||||
if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
|
||||
logerror("Could not bind to %s: %s",
|
||||
ip2str(ai->ai_family, ai->ai_addr, ai->ai_addrlen),
|
||||
ip2str(ai->ai_family, ai->ai_addr),
|
||||
strerror(errno));
|
||||
close(sockfd);
|
||||
continue; /* not fatal */
|
||||
}
|
||||
if (listen(sockfd, 5) < 0) {
|
||||
logerror("Could not listen to %s: %s",
|
||||
ip2str(ai->ai_family, ai->ai_addr, ai->ai_addrlen),
|
||||
ip2str(ai->ai_family, ai->ai_addr),
|
||||
strerror(errno));
|
||||
close(sockfd);
|
||||
continue; /* not fatal */
|
||||
@@ -1069,7 +1080,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
|
||||
|
||||
if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
|
||||
logerror("Could not bind to %s: %s",
|
||||
ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
|
||||
ip2str(AF_INET, (struct sockaddr *)&sin),
|
||||
strerror(errno));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
@@ -1077,7 +1088,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
|
||||
|
||||
if (listen(sockfd, 5) < 0) {
|
||||
logerror("Could not listen to %s: %s",
|
||||
ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
|
||||
ip2str(AF_INET, (struct sockaddr *)&sin),
|
||||
strerror(errno));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user