From: Marcus Meissner Date: Wed, 12 Feb 2014 19:58:43 +0000 (+0100) Subject: fixed socket existance checking X-Git-Tag: gnutls_3_3_0pre0~192 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0066189ed4cb9a2a990f3ee3accfc402f65094bc;p=thirdparty%2Fgnutls.git fixed socket existance checking If getaddrinfo returns: ipv4 address, ipv6 address ... and socket() for the ipv6 address fails, this loop would fail and abort the socket listen code. Signed-off-by: Nikos Mavrogiannopoulos --- diff --git a/src/serv.c b/src/serv.c index 60d4e970f1..c3e33ae529 100644 --- a/src/serv.c +++ b/src/serv.c @@ -712,7 +712,7 @@ int listen_socket(const char *name, int listen_port, int socktype) { struct addrinfo hints, *res, *ptr; char portname[6]; - int s; + int s = -1; int yes; listener_item *j = NULL; @@ -732,6 +732,7 @@ int listen_socket(const char *name, int listen_port, int socktype) } for (ptr = res; ptr != NULL; ptr = ptr->ai_next) { + int news; #ifndef HAVE_IPV6 if (ptr->ai_family != AF_INET) continue; @@ -747,11 +748,12 @@ int listen_socket(const char *name, int listen_port, int socktype) sizeof(topbuf))); } - if ((s = socket(ptr->ai_family, ptr->ai_socktype, + if ((news = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol)) < 0) { perror("socket() failed"); continue; } + s = news; /* to not overwrite existing s from previous loops */ #if defined(HAVE_IPV6) && !defined(_WIN32) if (ptr->ai_family == AF_INET6) { yes = 1;