Fix encoding of preferred_address transport parameter As per the spec, the connection ID length is encoded in one byte, not two. gfe-relnote: Fix encoding of preferred_address transport parameter, protected by disabled flag quic_supports_tls_handshake PiperOrigin-RevId: 246250892 Change-Id: I76b6df73e8240a492a90ba8139650b7bead71138
diff --git a/quic/core/crypto/transport_parameters.cc b/quic/core/crypto/transport_parameters.cc index 8982ae0..ee0ebf0 100644 --- a/quic/core/crypto/transport_parameters.cc +++ b/quic/core/crypto/transport_parameters.cc
@@ -472,8 +472,8 @@ v6_address_bytes.length()) || !CBB_add_u16(&preferred_address_params, in.preferred_address->ipv6_socket_address.port()) || - !CBB_add_u16_length_prefixed(&preferred_address_params, - &preferred_address_connection_id_param) || + !CBB_add_u8_length_prefixed(&preferred_address_params, + &preferred_address_connection_id_param) || !CBB_add_bytes(&preferred_address_connection_id_param, reinterpret_cast<const uint8_t*>( in.preferred_address->connection_id.data()), @@ -663,7 +663,7 @@ return false; } CBS connection_id_cbs; - if (!CBS_get_u16_length_prefixed(&value, &connection_id_cbs)) { + if (!CBS_get_u8_length_prefixed(&value, &connection_id_cbs)) { QUIC_DLOG(ERROR) << "Failed to parse length of preferred address connection ID"; return false;
diff --git a/quic/core/crypto/transport_parameters_test.cc b/quic/core/crypto/transport_parameters_test.cc index bf8ac51..7776af1 100644 --- a/quic/core/crypto/transport_parameters_test.cc +++ b/quic/core/crypto/transport_parameters_test.cc
@@ -47,7 +47,7 @@ QuicSocketAddress CreateFakeV4SocketAddress() { QuicIpAddress ipv4_address; - if (!ipv4_address.FromString("65.66.67.68")) { // 0x41424344 + if (!ipv4_address.FromString("65.66.67.68")) { // 0x41, 0x42, 0x43, 0x44 QUIC_LOG(FATAL) << "Failed to create IPv4 address"; return QuicSocketAddress(); } @@ -418,7 +418,7 @@ TEST_F(TransportParametersTest, ParseServerParams) { // clang-format off const uint8_t kServerParams[] = { - 0x00, 0xa3, // length of parameters array that follows + 0x00, 0xa2, // length of parameters array that follows // original_connection_id 0x00, 0x00, // parameter id 0x00, 0x08, // length @@ -473,13 +473,13 @@ 0x00, 0x00, // length // preferred_address 0x00, 0x0d, // parameter id - 0x00, 0x32, // length + 0x00, 0x31, // length 0x41, 0x42, 0x43, 0x44, // IPv4 address 0x48, 0x84, // IPv4 port 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, // IPv6 address 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x63, 0x36, // IPv6 port - 0x00, 0x08, // connection ID length + 0x08, // connection ID length 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xEF, // connection ID 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, // stateless reset token 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,