]> git.meshlink.io Git - meshlink/commitdiff
Fix NULL checking of addrinfo structure in try_bind function
authorLakshminarayana Gurram <38289425+lakshminarayanagurram@users.noreply.github.com>
Fri, 8 Mar 2019 05:10:59 +0000 (10:40 +0530)
committerGuus Sliepen <guus@meshlink.io>
Thu, 14 Mar 2019 20:22:50 +0000 (21:22 +0100)
src/meshlink.c

index 6f83c22fbd762a8bc68fd0c71b01af1aa1cdd844..9faccff4d737ca06a1068d2cfcd149012fcb0d97 100644 (file)
@@ -626,23 +626,22 @@ static bool try_bind(int port) {
                return false;
        }
 
-       while(ai) {
-               int fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
+       //while(ai) {
+       for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) {
+               int fd = socket(aip->ai_family, SOCK_STREAM, IPPROTO_TCP);
 
                if(!fd) {
                        freeaddrinfo(ai);
                        return false;
                }
 
-               int result = bind(fd, ai->ai_addr, ai->ai_addrlen);
+               int result = bind(fd, aip->ai_addr, aip->ai_addrlen);
                closesocket(fd);
 
                if(result) {
                        freeaddrinfo(ai);
                        return false;
                }
-
-               ai = ai->ai_next;
        }
 
        freeaddrinfo(ai);