From 25ca0ac73d7cd5b43cd4543aca91512519a39c6a Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Tue, 25 Jun 2019 10:40:48 -0700 Subject: [PATCH] Also fail CreateOffer and CreateAnswer if there is a session error Bug: chromium:974509 Change-Id: I952047dcf1e0fe5f3655bd94ea4b47c76655d262 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143843 Reviewed-by: Bjorn Mellem Commit-Queue: Steve Anton Cr-Commit-Position: refs/heads/master@{#28375} --- pc/peer_connection.cc | 22 ++++++++++++++++++++++ pc/peer_connection_crypto_unittest.cc | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 2de3075061..63d405b2b9 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -1973,6 +1973,17 @@ void PeerConnection::CreateOffer(CreateSessionDescriptionObserver* observer, return; } + // If a session error has occurred the PeerConnection is in a possibly + // inconsistent state so fail right away. + if (session_error() != SessionError::kNone) { + std::string error_message = GetSessionErrorMsg(); + RTC_LOG(LS_ERROR) << "CreateOffer: " << error_message; + PostCreateSessionDescriptionFailure( + observer, + RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error_message))); + return; + } + if (!ValidateOfferAnswerOptions(options)) { std::string error = "CreateOffer called with invalid options."; RTC_LOG(LS_ERROR) << error; @@ -2079,6 +2090,17 @@ void PeerConnection::CreateAnswer(CreateSessionDescriptionObserver* observer, return; } + // If a session error has occurred the PeerConnection is in a possibly + // inconsistent state so fail right away. + if (session_error() != SessionError::kNone) { + std::string error_message = GetSessionErrorMsg(); + RTC_LOG(LS_ERROR) << "CreateAnswer: " << error_message; + PostCreateSessionDescriptionFailure( + observer, + RTCError(RTCErrorType::INTERNAL_ERROR, std::move(error_message))); + return; + } + if (!(signaling_state_ == kHaveRemoteOffer || signaling_state_ == kHaveLocalPrAnswer)) { std::string error = diff --git a/pc/peer_connection_crypto_unittest.cc b/pc/peer_connection_crypto_unittest.cc index cb5c0e583f..f32a124961 100644 --- a/pc/peer_connection_crypto_unittest.cc +++ b/pc/peer_connection_crypto_unittest.cc @@ -720,7 +720,8 @@ TEST_P(PeerConnectionCryptoTest, SessionErrorIfFingerprintInvalid) { ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); // Create an invalid answer with the other certificate's fingerprint. - auto invalid_answer = callee->CreateAnswer(); + auto valid_answer = callee->CreateAnswer(); + auto invalid_answer = CloneSessionDescription(valid_answer.get()); auto* audio_content = cricket::GetFirstAudioContent(invalid_answer->description()); ASSERT_TRUE(audio_content); @@ -741,7 +742,7 @@ TEST_P(PeerConnectionCryptoTest, SessionErrorIfFingerprintInvalid) { ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error)); EXPECT_PRED_FORMAT2(AssertStringContains, error, "Session error code: ERROR_CONTENT."); - ASSERT_FALSE(callee->SetLocalDescription(callee->CreateAnswer(), &error)); + ASSERT_FALSE(callee->SetLocalDescription(std::move(valid_answer), &error)); EXPECT_PRED_FORMAT2(AssertStringContains, error, "Session error code: ERROR_CONTENT."); }