Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Unified Diff: webrtc/p2p/base/stunport.cc

Issue 1437933002: Fix a bug when we can't get default address (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: fix comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/stunport.cc
diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc
index ab8b2bff182999209b24887521d56cadea1df3e1..13ecca4a3a1cb90b2640e45ebee708d47cc2bf37 100644
--- a/webrtc/p2p/base/stunport.cc
+++ b/webrtc/p2p/base/stunport.cc
@@ -306,6 +306,9 @@ void UDPPort::OnLocalAddressReady(rtc::AsyncPacketSocket* socket,
// |emit_local_for_anyaddress| is true. This is to allow connectivity for
// applications which absolutely requires a HOST candidate.
rtc::SocketAddress addr = address;
+
+ // If MaybeSetDefaultLocalAddress fails, we keep the "any" IP so that at
+ // least the port is listening.
MaybeSetDefaultLocalAddress(&addr);
AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "",
@@ -404,17 +407,21 @@ void UDPPort::SendStunBindingRequest(const rtc::SocketAddress& stun_addr) {
}
}
-void UDPPort::MaybeSetDefaultLocalAddress(rtc::SocketAddress* addr) const {
+bool UDPPort::MaybeSetDefaultLocalAddress(rtc::SocketAddress* addr) const {
if (!addr->IsAnyIP() || !emit_local_for_anyaddress_ ||
!Network()->default_local_address_provider()) {
- return;
+ return true;
}
rtc::IPAddress default_address;
bool result =
Network()->default_local_address_provider()->GetDefaultLocalAddress(
addr->family(), &default_address);
- RTC_DCHECK(result && !default_address.IsNil());
+ if (!result || default_address.IsNil()) {
+ return false;
+ }
+
addr->SetIP(default_address);
+ return true;
}
void UDPPort::OnStunBindingRequestSucceeded(
@@ -434,8 +441,9 @@ void UDPPort::OnStunBindingRequestSucceeded(
!HasCandidateWithAddress(stun_reflected_addr)) {
rtc::SocketAddress related_address = socket_->GetLocalAddress();
- MaybeSetDefaultLocalAddress(&related_address);
- if (!(candidate_filter() & CF_HOST)) {
+ // If we can't stamp the related address correctly, empty it to avoid leak.
+ if (!MaybeSetDefaultLocalAddress(&related_address) ||
+ !(candidate_filter() & CF_HOST)) {
// If candidate filter doesn't have CF_HOST specified, empty raddr to
// avoid local address leakage.
related_address = rtc::EmptySocketAddressWithFamily(
« no previous file with comments | « webrtc/p2p/base/stunport.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698