tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 85e184fb2f285b3b0e628f186190dba36552fc05
parent 47c07156b95b586ce852e42b2b910960ea1b9d04
Author: Dan Baker <dbaker@mozilla.com>
Date:   Fri, 24 Oct 2025 12:58:13 -0600

Bug 1995393 - Vendor libwebrtc from 6012750735

Upstream commit: https://webrtc.googlesource.com/src/+/6012750735196dd13200d208117227ec6fb9f3f0
    Guard all non-const members of Port with thread_

    Bug: None
    Change-Id: I2eb555ee381d021ef6fa0f1c6d906269e89458a6
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/405380
    Commit-Queue: Harald Alvestrand <hta@webrtc.org>
    Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45393}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/p2p/base/port.cc | 24++++++++++++++++++++++++
Mthird_party/libwebrtc/p2p/base/port.h | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
3 files changed, 87 insertions(+), 31 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-24T18:55:29.191740+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-24T18:57:59.768033+00:00. # base of lastest vendoring -468589eae6 +6012750735 diff --git a/third_party/libwebrtc/p2p/base/port.cc b/third_party/libwebrtc/p2p/base/port.cc @@ -163,22 +163,27 @@ const Network* Port::Network() const { } IceRole Port::GetIceRole() const { + RTC_DCHECK_RUN_ON(thread_); return ice_role_; } void Port::SetIceRole(IceRole role) { + RTC_DCHECK_RUN_ON(thread_); ice_role_ = role; } void Port::SetIceTiebreaker(uint64_t tiebreaker) { + RTC_DCHECK_RUN_ON(thread_); tiebreaker_ = tiebreaker; } uint64_t Port::IceTiebreaker() const { + RTC_DCHECK_RUN_ON(thread_); return tiebreaker_; } bool Port::SharedSocket() const { + RTC_DCHECK_RUN_ON(thread_); return shared_socket_; } @@ -207,6 +212,7 @@ const std::vector<Candidate>& Port::Candidates() const { } Connection* Port::GetConnection(const SocketAddress& remote_addr) { + RTC_DCHECK_RUN_ON(thread_); AddressMap::const_iterator iter = connections_.find(remote_addr); if (iter != connections_.end()) return iter->second; @@ -311,14 +317,17 @@ void Port::PostAddAddress(bool is_final) { void Port::SubscribeCandidateError( std::function<void(Port*, const IceCandidateErrorEvent&)> callback) { + RTC_DCHECK_RUN_ON(thread_); candidate_error_callback_list_.AddReceiver(std::move(callback)); } void Port::SendCandidateError(const IceCandidateErrorEvent& event) { + RTC_DCHECK_RUN_ON(thread_); candidate_error_callback_list_.Send(this, event); } void Port::AddOrReplaceConnection(Connection* conn) { + RTC_DCHECK_RUN_ON(thread_); auto ret = connections_.insert( std::make_pair(conn->remote_candidate().address(), conn)); // If there is a different connection on the same remote address, replace @@ -337,6 +346,8 @@ void Port::AddOrReplaceConnection(Connection* conn) { } void Port::OnReadPacket(const ReceivedIpPacket& packet, ProtocolType proto) { + RTC_DCHECK_RUN_ON(thread_); + const char* data = reinterpret_cast<const char*>(packet.payload().data()); size_t size = packet.payload().size(); const SocketAddress& addr = packet.source_address(); @@ -392,6 +403,7 @@ void Port::OnReadPacket(const ReceivedIpPacket& packet, ProtocolType proto) { } void Port::OnReadyToSend() { + RTC_DCHECK_RUN_ON(thread_); AddressMap::iterator iter = connections_.begin(); for (; iter != connections_.end(); ++iter) { iter->second->OnReadyToSend(); @@ -800,6 +812,8 @@ void Port::SendUnknownAttributesErrorResponse( } void Port::KeepAliveUntilPruned() { + RTC_DCHECK_RUN_ON(thread_); + // If it is pruned, we won't bring it up again. if (state_ == State::INIT) { state_ = State::KEEP_ALIVE_UNTIL_PRUNED; @@ -807,6 +821,7 @@ void Port::KeepAliveUntilPruned() { } void Port::Prune() { + RTC_DCHECK_RUN_ON(thread_); state_ = State::PRUNED; PostDestroyIfDead(/*delayed=*/false); } @@ -819,6 +834,7 @@ void Port::CancelPendingTasks() { } void Port::PostDestroyIfDead(bool delayed) { + RTC_DCHECK_RUN_ON(thread_); WeakPtr<Port> weak_ptr = NewWeakPtr(); auto task = [weak_ptr = std::move(weak_ptr)] { if (weak_ptr) { @@ -847,10 +863,12 @@ void Port::DestroyIfDead() { void Port::SubscribePortDestroyed( std::function<void(PortInterface*)> callback) { + RTC_DCHECK_RUN_ON(thread_); port_destroyed_callback_list_.AddReceiver(std::move(callback)); } void Port::SendPortDestroyed(Port* port) { + RTC_DCHECK_RUN_ON(thread_); port_destroyed_callback_list_.Send(port); } void Port::OnNetworkTypeChanged(const ::webrtc::Network* network) { @@ -860,6 +878,7 @@ void Port::OnNetworkTypeChanged(const ::webrtc::Network* network) { } std::string Port::ToString() const { + RTC_DCHECK_RUN_ON(thread_); StringBuilder ss; ss << "Port[" << ToHex(reinterpret_cast<uintptr_t>(this)) << ":" << content_name_ << ":" << component_ << ":" << generation_ << ":" @@ -888,10 +907,12 @@ void Port::UpdateNetworkCost() { } void Port::EnablePortPackets() { + RTC_DCHECK_RUN_ON(thread_); enable_port_packets_ = true; } bool Port::OnConnectionDestroyed(Connection* conn) { + RTC_DCHECK_RUN_ON(thread_); if (connections_.erase(conn->remote_candidate().address()) == 0) { // This could indicate a programmer error outside of webrtc so while we // do have this check here to alert external developers, we also need to @@ -935,6 +956,7 @@ void Port::DestroyConnectionInternal(Connection* conn, bool async) { } void Port::Destroy() { + RTC_DCHECK_RUN_ON(thread_); RTC_DCHECK(connections_.empty()); RTC_LOG(LS_INFO) << ToString() << ": Port deleted"; SendPortDestroyed(this); @@ -954,6 +976,7 @@ void Port::CopyPortInformationToPacketInfo(PacketInfo* info) const { void Port::MaybeRequestLocalNetworkAccessPermission( const SocketAddress& address, absl::AnyInvocable<void(LocalNetworkAccessPermissionStatus)> callback) { + RTC_DCHECK_RUN_ON(thread_); if (!lna_permission_factory_) { std::move(callback)(LocalNetworkAccessPermissionStatus::kGranted); return; @@ -984,6 +1007,7 @@ void Port::OnRequestLocalNetworkAccessPermission( LocalNetworkAccessPermissionInterface* permission_query, absl::AnyInvocable<void(LocalNetworkAccessPermissionStatus)> callback, LocalNetworkAccessPermissionStatus status) { + RTC_DCHECK_RUN_ON(thread_); auto it = absl::c_find_if(permission_queries_, [permission_query](const auto& q) { return q.get() == permission_query; diff --git a/third_party/libwebrtc/p2p/base/port.h b/third_party/libwebrtc/p2p/base/port.h @@ -202,7 +202,10 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> { uint64_t IceTiebreaker() const override; bool SharedSocket() const override; - void ResetSharedSocket() { shared_socket_ = false; } + void ResetSharedSocket() { + RTC_DCHECK_RUN_ON(thread_); + shared_socket_ = false; + } // Should not destroy the port even if no connection is using it. Called when // a port is ready to use. @@ -222,22 +225,35 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> { // For debugging purposes. const std::string& content_name() const override { return content_name_; } void set_content_name(absl::string_view content_name) { + RTC_DCHECK_RUN_ON(thread_); content_name_ = std::string(content_name); } - int component() const { return component_; } - void set_component(int component) { component_ = component; } + int component() const { + RTC_DCHECK_RUN_ON(thread_); + return component_; + } + void set_component(int component) { + RTC_DCHECK_RUN_ON(thread_); + component_ = component; + } bool send_retransmit_count_attribute() const override { + RTC_DCHECK_RUN_ON(thread_); return send_retransmit_count_attribute_; } void set_send_retransmit_count_attribute(bool enable) { + RTC_DCHECK_RUN_ON(thread_); send_retransmit_count_attribute_ = enable; } // Identifies the generation that this port was created in. - uint32_t generation() const override { return generation_; } + uint32_t generation() const override { + RTC_DCHECK_RUN_ON(thread_); + return generation_; + } void set_generation(uint32_t generation) override { + RTC_DCHECK_RUN_ON(thread_); generation_ = generation; } @@ -324,8 +340,14 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> { // Debugging description of this port std::string ToString() const override; - uint16_t min_port() { return min_port_; } - uint16_t max_port() { return max_port_; } + uint16_t min_port() { + RTC_DCHECK_RUN_ON(thread_); + return min_port_; + } + uint16_t max_port() { + RTC_DCHECK_RUN_ON(thread_); + return max_port_; + } // Timeout shortening function to speed up unit tests. void set_timeout_delay(int delay); @@ -355,14 +377,20 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> { // Called when the Connection discovers a local peer reflexive candidate. void AddPrflxCandidate(const Candidate& local) override; - int16_t network_cost() const override { return network_cost_; } + int16_t network_cost() const override { + RTC_DCHECK_RUN_ON(thread_); + return network_cost_; + } void GetStunStats(std::optional<StunStats>* /* stats */) override {} protected: void UpdateNetworkCost() override; - WeakPtr<Port> NewWeakPtr() { return weak_factory_.GetWeakPtr(); } + WeakPtr<Port> NewWeakPtr() { + RTC_DCHECK_RUN_ON(thread_); + return weak_factory_.GetWeakPtr(); + } void AddAddress(const SocketAddress& address, const SocketAddress& base_address, @@ -428,9 +456,12 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> { void CopyPortInformationToPacketInfo(PacketInfo* info) const; MdnsNameRegistrationStatus mdns_name_registration_status() const { + RTC_DCHECK_RUN_ON(thread_); + return mdns_name_registration_status_; } void set_mdns_name_registration_status(MdnsNameRegistrationStatus status) { + RTC_DCHECK_RUN_ON(thread_); mdns_name_registration_status_ = status; } @@ -479,13 +510,13 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> { PacketSocketFactory* const factory_; LocalNetworkAccessPermissionFactoryInterface* const lna_permission_factory_; const IceCandidateType type_; - bool send_retransmit_count_attribute_; + bool send_retransmit_count_attribute_ RTC_GUARDED_BY(thread_); const ::webrtc::Network* network_; - uint16_t min_port_; - uint16_t max_port_; - std::string content_name_; - int component_; - uint32_t generation_; + uint16_t min_port_ RTC_GUARDED_BY(thread_); + uint16_t max_port_ RTC_GUARDED_BY(thread_); + std::string content_name_ RTC_GUARDED_BY(thread_); + int component_ RTC_GUARDED_BY(thread_); + uint32_t generation_ RTC_GUARDED_BY(thread_); // In order to establish a connection to this Port (so that real data can be // sent through), the other side must send us a STUN binding request that is // authenticated with this username_fragment and password. @@ -493,37 +524,38 @@ class RTC_EXPORT Port : public PortInterface, public sigslot::has_slots<> { std::string ice_username_fragment_ RTC_GUARDED_BY(thread_); std::string password_ RTC_GUARDED_BY(thread_); std::vector<Candidate> candidates_ RTC_GUARDED_BY(thread_); - AddressMap connections_; - int timeout_delay_; - bool enable_port_packets_; - IceRole ice_role_; - uint64_t tiebreaker_; - bool shared_socket_; + AddressMap connections_ RTC_GUARDED_BY(thread_); + int timeout_delay_ RTC_GUARDED_BY(thread_); + bool enable_port_packets_ RTC_GUARDED_BY(thread_); + IceRole ice_role_ RTC_GUARDED_BY(thread_); + uint64_t tiebreaker_ RTC_GUARDED_BY(thread_); + bool shared_socket_ RTC_GUARDED_BY(thread_); // A virtual cost perceived by the user, usually based on the network type // (WiFi. vs. Cellular). It takes precedence over the priority when // comparing two connections. - int16_t network_cost_; + int16_t network_cost_ RTC_GUARDED_BY(thread_); // INIT: The state when a port is just created. // KEEP_ALIVE_UNTIL_PRUNED: A port should not be destroyed even if no // connection is using it. // PRUNED: It will be destroyed if no connection is using it for a period of // 30 seconds. enum class State { INIT, KEEP_ALIVE_UNTIL_PRUNED, PRUNED }; - State state_ = State::INIT; - int64_t last_time_all_connections_removed_ = 0; - MdnsNameRegistrationStatus mdns_name_registration_status_ = - MdnsNameRegistrationStatus::kNotStarted; + State state_ RTC_GUARDED_BY(thread_) = State::INIT; + int64_t last_time_all_connections_removed_ RTC_GUARDED_BY(thread_) = 0; + MdnsNameRegistrationStatus mdns_name_registration_status_ + RTC_GUARDED_BY(thread_) = MdnsNameRegistrationStatus::kNotStarted; std::vector<std::unique_ptr<LocalNetworkAccessPermissionInterface>> - permission_queries_; + permission_queries_ RTC_GUARDED_BY(thread_); - CallbackList<PortInterface*> port_destroyed_callback_list_; + CallbackList<PortInterface*> port_destroyed_callback_list_ + RTC_GUARDED_BY(thread_); CallbackList<Port*, const IceCandidateErrorEvent&> - candidate_error_callback_list_; + candidate_error_callback_list_ RTC_GUARDED_BY(thread_); // Keep as the last member variable. - WeakPtrFactory<Port> weak_factory_; + WeakPtrFactory<Port> weak_factory_ RTC_GUARDED_BY(thread_); }; } // namespace webrtc