diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index 18a84d02ee..6c2110a873 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc @@ -312,6 +312,20 @@ TurnPort::~TurnPort() { } } +void TurnPort::set_realm(absl::string_view realm) { + if (realm.empty()) { + // Fail silently since this reduces the entropy going into the hash but log + // a warning. + RTC_LOG(LS_WARNING) << "Setting realm to the empty string, " + << "this is not supported."; + return; + } + if (realm != realm_) { + realm_ = std::string(realm); + UpdateHash(); + } +} + rtc::SocketAddress TurnPort::GetLocalAddress() const { return socket_ ? socket_->GetLocalAddress() : rtc::SocketAddress(); } diff --git a/p2p/base/turn_port.h b/p2p/base/turn_port.h index 099d8b258a..69832aef7f 100644 --- a/p2p/base/turn_port.h +++ b/p2p/base/turn_port.h @@ -252,12 +252,7 @@ class TurnPort : public Port { bool CreateTurnClientSocket(); void set_nonce(absl::string_view nonce) { nonce_ = std::string(nonce); } - void set_realm(absl::string_view realm) { - if (realm != realm_) { - realm_ = std::string(realm); - UpdateHash(); - } - } + void set_realm(absl::string_view realm); void OnRefreshError(); void HandleRefreshError();