From a3f2e7200877fbceaf2c3c6d475774198fd1f00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Tue, 26 Jul 2022 10:30:49 +0200 Subject: [PATCH] Fix potential UAF in unit test. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In WebRtcVideoChannelBaseTest.EncoderSelectorSwitchCodec a mock encoder selecter or stack allocated and then registered with the channel. Since this test uses real-time clocks/threads, there is a chance that the selector callback will be called after the mock goes out of scope, but before the test had time to be torn down. This CL fixes that by simply de-registering the callback before the end of the test. Bug: b/239855550 Change-Id: Ibb38a914933494fd04c963b9a13f2cc4aee160d6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/269402 Auto-Submit: Erik Språng Reviewed-by: Mirko Bonadei Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#37618} --- media/engine/webrtc_video_engine_unittest.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc index ae5c6b3a93..93c086b2e7 100644 --- a/media/engine/webrtc_video_engine_unittest.cc +++ b/media/engine/webrtc_video_engine_unittest.cc @@ -9036,6 +9036,9 @@ TEST_F(WebRtcVideoChannelBaseTest, EncoderSelectorSwitchCodec) { ASSERT_TRUE(channel_->GetSendCodec(&codec)); EXPECT_EQ("VP9", codec.name); + + // Deregister the encoder selector in case it's called during test tear-down. + channel_->SetEncoderSelector(kSsrc, nullptr); } } // namespace cricket