From ad631f0d353011b8d4282577310abb48bf60ff67 Mon Sep 17 00:00:00 2001 From: Daniel Cheng Date: Sat, 2 Dec 2023 14:16:59 -0800 Subject: [PATCH] Correctly const-qualify return value of IceControllerInterface::connections(). This is intended to be a read-only view across a container of const Connection*, but due to the missing const, elements of the container could actually be re-assigned through the ArrayView. This was discovered when trying to roll Googletest, since Googletest was fixed to const-qualify converting actions: https://github.com/google/googletest/commit/cbca6bc3957b28b8062f20b65f9349d94a4bf0b3 Bug: chromium:1409870 Change-Id: Iadd3abe6807111987e422b8510a23f2a4f7026ed Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/329481 Auto-Submit: Daniel Cheng Reviewed-by: Harald Alvestrand Commit-Queue: Harald Alvestrand Commit-Queue: Daniel Cheng Cr-Commit-Position: refs/heads/main@{#41300} --- p2p/base/basic_ice_controller.h | 6 ++---- p2p/base/ice_controller_interface.h | 2 +- p2p/base/mock_ice_controller.h | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/p2p/base/basic_ice_controller.h b/p2p/base/basic_ice_controller.h index b941a0dd7e..ba14d80474 100644 --- a/p2p/base/basic_ice_controller.h +++ b/p2p/base/basic_ice_controller.h @@ -32,10 +32,8 @@ class BasicIceController : public IceControllerInterface { void SetSelectedConnection(const Connection* selected_connection) override; void AddConnection(const Connection* connection) override; void OnConnectionDestroyed(const Connection* connection) override; - rtc::ArrayView connections() const override { - return rtc::ArrayView( - const_cast(connections_.data()), - connections_.size()); + rtc::ArrayView connections() const override { + return connections_; } bool HasPingableConnection() const override; diff --git a/p2p/base/ice_controller_interface.h b/p2p/base/ice_controller_interface.h index 8b63ed3fc3..adedf4c604 100644 --- a/p2p/base/ice_controller_interface.h +++ b/p2p/base/ice_controller_interface.h @@ -101,7 +101,7 @@ class IceControllerInterface { virtual void OnConnectionDestroyed(const Connection* connection) = 0; // These are all connections that has been added and not destroyed. - virtual rtc::ArrayView connections() const = 0; + virtual rtc::ArrayView connections() const = 0; // Is there a pingable connection ? // This function is used to boot-strap pinging, after this returns true diff --git a/p2p/base/mock_ice_controller.h b/p2p/base/mock_ice_controller.h index bde9254e7d..02468402ac 100644 --- a/p2p/base/mock_ice_controller.h +++ b/p2p/base/mock_ice_controller.h @@ -35,7 +35,7 @@ class MockIceController : public cricket::IceControllerInterface { OnConnectionDestroyed, (const cricket::Connection*), (override)); - MOCK_METHOD(rtc::ArrayView, + MOCK_METHOD(rtc::ArrayView, connections, (), (const, override));