Remove fields from remote candidates that could cause crashes in GetStats

Typically, remote candidates come from signalling and are deserialized
into C++ objects. The network_type field of these candidates is
always ADAPTER_TYPE_UNKNOWN.

However, in tests it is common to pass SDP and remote candidates as C++
objects. In this case, the network_type property of remote candidates
is preserved, so DCHECK might be triggered when GetStats is called.

Clearing fields that are not suitable as remote candidates fixes
this issue.

Bug: None
Change-Id: Ida01b0224bce5cf3e87bcad1ddaca35c9f4fffe7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279680
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Auto-Submit: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38436}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index ed6cd99..82e5942 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -2605,8 +2605,19 @@
                                         const cricket::Candidate& candidate) {
   RTC_DCHECK_RUN_ON(signaling_thread());
 
+  if (candidate.network_type() != rtc::ADAPTER_TYPE_UNKNOWN) {
+    RTC_DLOG(LS_WARNING) << "Using candidate with adapter type set - this "
+                            "should only happen in test";
+  }
+
+  // Clear fields that do not make sense as remote candidates.
+  cricket::Candidate new_candidate(candidate);
+  new_candidate.set_network_type(rtc::ADAPTER_TYPE_UNKNOWN);
+  new_candidate.set_relay_protocol("");
+  new_candidate.set_underlying_type_for_vpn(rtc::ADAPTER_TYPE_UNKNOWN);
+
   network_thread()->PostTask(SafeTask(
-      network_thread_safety_, [this, mid = mid, candidate = candidate] {
+      network_thread_safety_, [this, mid = mid, candidate = new_candidate] {
         RTC_DCHECK_RUN_ON(network_thread());
         std::vector<cricket::Candidate> candidates = {candidate};
         RTCError error =