From dbca2f98898854045ea406d93b2212a04730f771 Mon Sep 17 00:00:00 2001 From: Stephanie Wang Date: Fri, 11 Sep 2020 15:35:03 -0700 Subject: [PATCH] Fix segfault in network utils (#10741) --- src/ray/common/network_util.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ray/common/network_util.cc b/src/ray/common/network_util.cc index 9494b9ebc..c39e18a25 100644 --- a/src/ray/common/network_util.cc +++ b/src/ray/common/network_util.cc @@ -97,7 +97,7 @@ std::vector GetValidLocalIpCandidates() { struct ifaddrs *if_info = nullptr; for (if_info = ifs_info; if_info != nullptr; if_info = if_info->ifa_next) { - if (if_info->ifa_addr->sa_family == AF_INET) { + if (if_info->ifa_addr && if_info->ifa_addr->sa_family == AF_INET) { void *addr = &((struct sockaddr_in *)if_info->ifa_addr)->sin_addr; char ip[INET_ADDRSTRLEN]; @@ -115,7 +115,8 @@ std::vector GetValidLocalIpCandidates() { // Filter out interfaces with small possibility of being desired to be used to serve std::sort(ifnames_and_ips.begin(), ifnames_and_ips.end(), CompNamesAndIps); - while (GetPriority(ifnames_and_ips.back().first) == Priority::kExclude) { + while (!ifnames_and_ips.empty() && + GetPriority(ifnames_and_ips.back().first) == Priority::kExclude) { ifnames_and_ips.pop_back(); }