Copy cached transport parameters and application states instead of using pointers in QUIC 0-RTT setup.

There is currently a time gap between looking up the cache and using the cache. During this gap, the cache could be invalidated.

Client side change. not protected.

PiperOrigin-RevId: 327337399
Change-Id: I04bc99d8cf77b613f635e1da91d75c8269cf9e95
diff --git a/quic/core/crypto/quic_crypto_client_config.h b/quic/core/crypto/quic_crypto_client_config.h
index 3d90757..701b7ff 100644
--- a/quic/core/crypto/quic_crypto_client_config.h
+++ b/quic/core/crypto/quic_crypto_client_config.h
@@ -42,13 +42,13 @@
   // client didn't receive a 0-RTT capable session ticket from the server,
   // |transport_params| will be null. Otherwise, it will contain the transport
   // parameters received from the server on the original connection.
-  TransportParameters* transport_params;
+  std::unique_ptr<TransportParameters> transport_params = nullptr;
 
   // If |transport_params| is null, then |application_state| is ignored and
   // should be empty. |application_state| contains serialized state that the
   // client received from the server at the application layer that the client
   // needs to remember when performing a 0-RTT handshake.
-  ApplicationState* application_state;
+  std::unique_ptr<ApplicationState> application_state = nullptr;
 };
 
 // SessionCache is an interface for managing storing and retrieving
diff --git a/quic/core/tls_client_handshaker.cc b/quic/core/tls_client_handshaker.cc
index 265496d..dfaab51 100644
--- a/quic/core/tls_client_handshaker.cc
+++ b/quic/core/tls_client_handshaker.cc
@@ -130,7 +130,8 @@
 bool TlsClientHandshaker::PrepareZeroRttConfig(
     QuicResumptionState* cached_state) {
   std::string error_details;
-  if (handshaker_delegate()->ProcessTransportParameters(
+  if (!cached_state->transport_params ||
+      handshaker_delegate()->ProcessTransportParameters(
           *(cached_state->transport_params),
           /*is_resumption = */ true, &error_details) != QUIC_NO_ERROR) {
     QUIC_BUG << "Unable to parse cached transport parameters.";
@@ -144,7 +145,9 @@
   session()->OnConfigNegotiated();
 
   if (has_application_state_) {
-    if (!session()->ResumeApplicationState(cached_state->application_state)) {
+    if (!cached_state->application_state ||
+        !session()->ResumeApplicationState(
+            cached_state->application_state.get())) {
       QUIC_BUG << "Unable to parse cached application state.";
       CloseConnection(QUIC_HANDSHAKE_FAILED,
                       "Client failed to parse cached application state.");