From 026aa799bdccd860575e4ce228b750f47abd31e2 Mon Sep 17 00:00:00 2001 From: Lakshminarayana Gurram <38289425+lakshminarayanagurram@users.noreply.github.com> Date: Fri, 8 Mar 2019 10:40:59 +0530 Subject: [PATCH] Fix NULL checking of addrinfo structure in try_bind function --- src/meshlink.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 6f83c22f..9faccff4 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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); -- 2.39.5