aboutsummaryrefslogtreecommitdiff
path: root/webrtc/p2p
diff options
context:
space:
mode:
authorGuo-wei Shieh <guoweis@webrtc.org>2015-11-11 11:11:19 -0800
committerGuo-wei Shieh <guoweis@webrtc.org>2015-11-11 19:11:28 +0000
commite03cab94c1bac43f4d6c4775023a957f98ee8132 (patch)
treefb25258c50d0c062ce2289185f5c47549f5d3c7b /webrtc/p2p
parentee2bac26dd3eb4463126098f87701ff66098b288 (diff)
downloadwebrtc-e03cab94c1bac43f4d6c4775023a957f98ee8132.tar.gz
When running this code in chromium on a machine with IPv6 disabled, the RTC_DCHECK fails and in release build, it could leak to further crash in chromium's rtc_peer_connection_hanlder.cc.
Here is the right fix. BUG=webrtc:5061 R=pthatcher@google.com TBR=pthatcher@webrtc.org Review URL: https://codereview.webrtc.org/1437933002 . Cr-Commit-Position: refs/heads/master@{#10607}
Diffstat (limited to 'webrtc/p2p')
-rw-r--r--webrtc/p2p/base/stunport.cc18
-rw-r--r--webrtc/p2p/base/stunport.h6
2 files changed, 17 insertions, 7 deletions
diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc
index ab8b2bff18..13ecca4a3a 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(
diff --git a/webrtc/p2p/base/stunport.h b/webrtc/p2p/base/stunport.h
index 6e7a239578..ccd3f36cc3 100644
--- a/webrtc/p2p/base/stunport.h
+++ b/webrtc/p2p/base/stunport.h
@@ -149,8 +149,10 @@ class UDPPort : public Port {
void SendStunBindingRequests();
// Helper function which will set |addr|'s IP to the default local address if
- // |addr| is the "any" address and |emit_local_for_anyaddress_| is true.
- void MaybeSetDefaultLocalAddress(rtc::SocketAddress* addr) const;
+ // |addr| is the "any" address and |emit_local_for_anyaddress_| is true. When
+ // returning false, it indicates that the operation has failed and the
+ // address shouldn't be used by any candidate.
+ bool MaybeSetDefaultLocalAddress(rtc::SocketAddress* addr) const;
private:
// A helper class which can be called repeatedly to resolve multiple