]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
fixed socket existance checking
authorMarcus Meissner <meissner@suse.de>
Wed, 12 Feb 2014 19:58:43 +0000 (20:58 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 12 Feb 2014 21:34:51 +0000 (22:34 +0100)
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 <nmav@gnutls.org>
src/serv.c

index 60d4e970f11d9a22189948fd1334b268432cc2f8..c3e33ae529627b0085c495bb572d767746adc94b 100644 (file)
@@ -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;