Check if ifa_addr field is null.
This field can be null. See e.g. https://man7.org/linux/man-pages/man3/getifaddrs.3.html
Bug: webrtc:12523
Change-Id: I63ba297d0c57b3b70c545d1434716094d8ce20a4
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212601
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33517}
diff --git a/rtc_base/net_helpers.cc b/rtc_base/net_helpers.cc
index e51a51a..bec854a 100644
--- a/rtc_base/net_helpers.cc
+++ b/rtc_base/net_helpers.cc
@@ -53,7 +53,7 @@
return false;
}
for (struct ifaddrs* cur = ifa; cur != nullptr; cur = cur->ifa_next) {
- if (cur->ifa_addr->sa_family == AF_INET) {
+ if (cur->ifa_addr != nullptr && cur->ifa_addr->sa_family == AF_INET) {
has_ipv4 = true;
break;
}
@@ -112,7 +112,7 @@
return false;
}
for (struct ifaddrs* cur = ifa; cur != nullptr; cur = cur->ifa_next) {
- if (cur->ifa_addr->sa_family == AF_INET6) {
+ if (cur->ifa_addr != nullptr && cur->ifa_addr->sa_family == AF_INET6) {
has_ipv6 = true;
break;
}