From fca4d442ce89296578f98f6cc9e03a6388f97167 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 11 Jul 2023 17:44:09 -0700 Subject: [PATCH 01/11] add new parameter --- src/core/connection.c | 24 ++++++++++++++++++++++++ src/inc/msquic.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/core/connection.c b/src/core/connection.c index 79d2f47a2d..48d37596f5 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -6820,6 +6820,30 @@ QuicConnParamGet( uint8_t Type; switch (Param) { + + case QUICK_PARAM_CONN_ORIG_DEST_CID: + if (Connection == NULL) { + Status = QUIC_STATUS_INVALID_STATE; + break; + } + if (Buffer == NULL) { + Status = QUIC_STATUS_INVALID_PARAMETER; + break; + } + if (*BufferLength < Connection->OrigDestCID->Length) { + // Tell app it needs to pass in a bigger buffer. + Status = QUIC_STATUS_BUFFER_TOO_SMALL; + // Let app know this is the size buffer it needs. + *BufferLength = Connection->OrigDestCID->Length; + break; + } + CxPlatCopyMemory( + Connection->OrigDestCID->Data, + Buffer, + Connection->OrigDestCID->Length); + // Tell app how much buffer we copied. + *BufferLength = Connection->OrigDestCID->Length; + break; case QUIC_PARAM_CONN_QUIC_VERSION: diff --git a/src/inc/msquic.h b/src/inc/msquic.h index 5f26d70fd7..3ecd3914e7 100644 --- a/src/inc/msquic.h +++ b/src/inc/msquic.h @@ -889,6 +889,7 @@ typedef struct QUIC_SCHANNEL_CREDENTIAL_ATTRIBUTE_W { #endif #define QUIC_PARAM_CONN_STATISTICS_V2 0x05000016 // QUIC_STATISTICS_V2 #define QUIC_PARAM_CONN_STATISTICS_V2_PLAT 0x05000017 // QUIC_STATISTICS_V2 +#define QUICK_PARAM_CONN_ORIG_DEST_CID 0x05000018 // uint8_t[] // // Parameters for TLS. From b25e9f3145dd7e7a376c6bc39422df466d459860 Mon Sep 17 00:00:00 2001 From: Jack He Date: Wed, 12 Jul 2023 10:25:11 -0700 Subject: [PATCH 02/11] remember to set success status --- src/core/connection.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/connection.c b/src/core/connection.c index 48d37596f5..858d0215d6 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -6843,6 +6843,7 @@ QuicConnParamGet( Connection->OrigDestCID->Length); // Tell app how much buffer we copied. *BufferLength = Connection->OrigDestCID->Length; + Status = QUIC_STATUS_SUCCESS; break; case QUIC_PARAM_CONN_QUIC_VERSION: From 1416f780f1ca6887fe0aa2a85c8a788acfec398b Mon Sep 17 00:00:00 2001 From: Jack He Date: Wed, 12 Jul 2023 17:00:51 -0700 Subject: [PATCH 03/11] add test cases --- docs/Settings.md | 2 +- src/core/connection.c | 4 ++-- src/inc/msquic.h | 2 +- src/test/lib/ApiTest.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index 7aa2db9a03..9ab04d323d 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -168,7 +168,7 @@ These parameters are accessed by calling [GetParam](./api/GetParam.md) or [SetPa | `QUIC_PARAM_CONN_CIBIR_ID`
21 | uint8_t[] | Set-only | The CIBIR well-known identifier. | | `QUIC_PARAM_CONN_STATISTICS_V2`
22 | QUIC_STATISTICS_V2 | Get-only | Connection-level statistics, version 2. | | `QUIC_PARAM_CONN_STATISTICS_V2_PLAT`
23 | QUIC_STATISTICS_V2 | Get-only | Connection-level statistics with platform-specific time format, version 2. | - +| `QUIC_PARAM_CONN_ORIG_DEST_CID`
24 | uint8_t[] | Get-only | CID information about the original client that made the connection to the server. | ### QUIC_PARAM_CONN_STATISTICS_V2 Querying the `QUIC_STATISTICS_V2` struct via `QUIC_PARAM_CONN_STATISTICS_V2` or `QUIC_PARAM_CONN_STATISTICS_V2_PLAT` should be aware of possible changes in the size of the struct, depending on the version of MsQuic the app using at runtime, not just what it was compiled against. diff --git a/src/core/connection.c b/src/core/connection.c index 858d0215d6..6e2b80d2db 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -6821,8 +6821,8 @@ QuicConnParamGet( switch (Param) { - case QUICK_PARAM_CONN_ORIG_DEST_CID: - if (Connection == NULL) { + case QUIC_PARAM_CONN_ORIG_DEST_CID: + if (Connection == NULL || Connection->OrigDestCID == NULL) { Status = QUIC_STATUS_INVALID_STATE; break; } diff --git a/src/inc/msquic.h b/src/inc/msquic.h index 3ecd3914e7..ad9c5b4a14 100644 --- a/src/inc/msquic.h +++ b/src/inc/msquic.h @@ -889,7 +889,7 @@ typedef struct QUIC_SCHANNEL_CREDENTIAL_ATTRIBUTE_W { #endif #define QUIC_PARAM_CONN_STATISTICS_V2 0x05000016 // QUIC_STATISTICS_V2 #define QUIC_PARAM_CONN_STATISTICS_V2_PLAT 0x05000017 // QUIC_STATISTICS_V2 -#define QUICK_PARAM_CONN_ORIG_DEST_CID 0x05000018 // uint8_t[] +#define QUIC_PARAM_CONN_ORIG_DEST_CID 0x05000018 // uint8_t[] // // Parameters for TLS. diff --git a/src/test/lib/ApiTest.cpp b/src/test/lib/ApiTest.cpp index 0db436989e..fa0eaaea5b 100644 --- a/src/test/lib/ApiTest.cpp +++ b/src/test/lib/ApiTest.cpp @@ -4227,6 +4227,56 @@ void QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(MsQuicRegistration& Registratio } } + +void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { + // This is the unit test for checking to see if a server has the correct original dest CID. + TestScopeLogger LogScope0("QUIC_PARAM_CONN_ORIG_DEST_CID"); + { + MsQuicConnection Connection(Registration); + TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); + uint32_t SizeOfBuffer = 8; // 8 bytes is the expected minimum size of the CID. + TestScopeLogger LogScope1("GetParam test success case"); + QUIC_BUFFER buffer = {SizeOfBuffer, new uint8_t[SizeOfBuffer]}; + TEST_QUIC_STATUS( + QUIC_STATUS_SUCCESS, + Connection.GetParam( + QUIC_PARAM_CONN_ORIG_DEST_CID, + &SizeOfBuffer, + &buffer + ) + ) + } + { + MsQuicConnection Connection(Registration); + TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); + uint32_t SizeOfBuffer = 8; + TestScopeLogger LogScope1("GetParam null buffer check"); + TEST_QUIC_STATUS( + QUIC_STATUS_INVALID_PARAMETER, + Connection.GetParam( + QUIC_PARAM_CONN_ORIG_DEST_CID, + &SizeOfBuffer, + nullptr + ) + ) + } + { + MsQuicConnection Connection(Registration); + TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); + uint32_t SizeOfBuffer = 1; + TestScopeLogger LogScope1("GetParam buffer too small check"); + QUIC_BUFFER buffer = {SizeOfBuffer, new uint8_t[SizeOfBuffer]}; + TEST_QUIC_STATUS( + QUIC_STATUS_BUFFER_TOO_SMALL, + Connection.GetParam( + QUIC_PARAM_CONN_ORIG_DEST_CID, + &SizeOfBuffer, + &buffer + ) + ) + } +} + void QuicTestConnectionParam() { MsQuicAlpn Alpn("MsQuicTest"); @@ -4259,6 +4309,7 @@ void QuicTestConnectionParam() QuicTest_QUIC_PARAM_CONN_CIBIR_ID(Registration, ClientConfiguration); QuicTest_QUIC_PARAM_CONN_STATISTICS_V2(Registration); QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(Registration); + QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(Registration); } // From ee71aca0212869890a1f88d4834490c7e1ee511b Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 13 Jul 2023 11:05:59 -0700 Subject: [PATCH 04/11] fix test cases --- src/core/connection.c | 2 +- src/test/lib/ApiTest.cpp | 67 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/core/connection.c b/src/core/connection.c index 6e2b80d2db..e1cabb825a 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -6822,7 +6822,7 @@ QuicConnParamGet( switch (Param) { case QUIC_PARAM_CONN_ORIG_DEST_CID: - if (Connection == NULL || Connection->OrigDestCID == NULL) { + if (Connection->OrigDestCID == NULL) { Status = QUIC_STATUS_INVALID_STATE; break; } diff --git a/src/test/lib/ApiTest.cpp b/src/test/lib/ApiTest.cpp index fa0eaaea5b..67df0960b0 100644 --- a/src/test/lib/ApiTest.cpp +++ b/src/test/lib/ApiTest.cpp @@ -4229,26 +4229,46 @@ void QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(MsQuicRegistration& Registratio void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { + // // This is the unit test for checking to see if a server has the correct original dest CID. + // TestScopeLogger LogScope0("QUIC_PARAM_CONN_ORIG_DEST_CID"); { MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); - uint32_t SizeOfBuffer = 8; // 8 bytes is the expected minimum size of the CID. + MsQuicAlpn Alpn("MsQuicTest"); + MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); + TEST_QUIC_SUCCEEDED( + MsQuic->ConnectionStart( + Connection.Handle, + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); + uint32_t SizeOfBuffer = 8; + uint8_t Buffer[8]; // 8 bytes is the expected minimum size of the CID. TestScopeLogger LogScope1("GetParam test success case"); - QUIC_BUFFER buffer = {SizeOfBuffer, new uint8_t[SizeOfBuffer]}; TEST_QUIC_STATUS( QUIC_STATUS_SUCCESS, Connection.GetParam( QUIC_PARAM_CONN_ORIG_DEST_CID, &SizeOfBuffer, - &buffer + Buffer ) ) } { MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); + MsQuicAlpn Alpn("MsQuicTest"); + MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); + TEST_QUIC_SUCCEEDED( + MsQuic->ConnectionStart( + Connection.Handle, + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); uint32_t SizeOfBuffer = 8; TestScopeLogger LogScope1("GetParam null buffer check"); TEST_QUIC_STATUS( @@ -4263,18 +4283,55 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { { MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); + MsQuicAlpn Alpn("MsQuicTest"); + MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); + TEST_QUIC_SUCCEEDED( + MsQuic->ConnectionStart( + Connection.Handle, + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); uint32_t SizeOfBuffer = 1; TestScopeLogger LogScope1("GetParam buffer too small check"); - QUIC_BUFFER buffer = {SizeOfBuffer, new uint8_t[SizeOfBuffer]}; + uint8_t Buffer[1]; TEST_QUIC_STATUS( QUIC_STATUS_BUFFER_TOO_SMALL, Connection.GetParam( QUIC_PARAM_CONN_ORIG_DEST_CID, &SizeOfBuffer, - &buffer + Buffer ) ) } + { + MsQuicConnection Connection(Registration); + TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); + MsQuicAlpn Alpn("MsQuicTest"); + MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); + TEST_QUIC_SUCCEEDED( + MsQuic->ConnectionStart( + Connection.Handle, + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); + uint32_t SizeOfBuffer = 100; + uint8_t Buffer[100]; + TestScopeLogger LogScope1("GetParam size of buffer bigger than needed"); + TEST_QUIC_STATUS( + QUIC_STATUS_SUCCESS, + Connection.GetParam( + QUIC_PARAM_CONN_ORIG_DEST_CID, + &SizeOfBuffer, + Buffer + ) + ) + // + // There is no way the CID written should be 100 bytes. + // + TEST_TRUE(SizeOfBuffer < 100); + } } void QuicTestConnectionParam() From 42fe61e856b125c610fe5d73b383821523ac93cd Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 13 Jul 2023 11:11:23 -0700 Subject: [PATCH 05/11] fix styling --- src/core/connection.c | 50 ++++++++++++++++++++-------------------- src/test/lib/ApiTest.cpp | 7 ++++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/core/connection.c b/src/core/connection.c index e1cabb825a..036290699d 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -6820,31 +6820,6 @@ QuicConnParamGet( uint8_t Type; switch (Param) { - - case QUIC_PARAM_CONN_ORIG_DEST_CID: - if (Connection->OrigDestCID == NULL) { - Status = QUIC_STATUS_INVALID_STATE; - break; - } - if (Buffer == NULL) { - Status = QUIC_STATUS_INVALID_PARAMETER; - break; - } - if (*BufferLength < Connection->OrigDestCID->Length) { - // Tell app it needs to pass in a bigger buffer. - Status = QUIC_STATUS_BUFFER_TOO_SMALL; - // Let app know this is the size buffer it needs. - *BufferLength = Connection->OrigDestCID->Length; - break; - } - CxPlatCopyMemory( - Connection->OrigDestCID->Data, - Buffer, - Connection->OrigDestCID->Length); - // Tell app how much buffer we copied. - *BufferLength = Connection->OrigDestCID->Length; - Status = QUIC_STATUS_SUCCESS; - break; case QUIC_PARAM_CONN_QUIC_VERSION: @@ -7195,6 +7170,31 @@ QuicConnParamGet( break; } + case QUIC_PARAM_CONN_ORIG_DEST_CID: + if (Connection->OrigDestCID == NULL) { + Status = QUIC_STATUS_INVALID_STATE; + break; + } + if (Buffer == NULL) { + Status = QUIC_STATUS_INVALID_PARAMETER; + break; + } + if (*BufferLength < Connection->OrigDestCID->Length) { + Status = QUIC_STATUS_BUFFER_TOO_SMALL; + *BufferLength = Connection->OrigDestCID->Length; + break; + } + CxPlatCopyMemory( + Connection->OrigDestCID->Data, + Buffer, + Connection->OrigDestCID->Length); + // + // Tell app how much buffer we copied. + // + *BufferLength = Connection->OrigDestCID->Length; + Status = QUIC_STATUS_SUCCESS; + break; + default: Status = QUIC_STATUS_INVALID_PARAMETER; break; diff --git a/src/test/lib/ApiTest.cpp b/src/test/lib/ApiTest.cpp index 67df0960b0..e2e6495e01 100644 --- a/src/test/lib/ApiTest.cpp +++ b/src/test/lib/ApiTest.cpp @@ -4245,8 +4245,11 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { QUIC_ADDRESS_FAMILY_INET, "localhost", 4433)); + // + // 8 bytes is the expected minimum size of the CID. + // uint32_t SizeOfBuffer = 8; - uint8_t Buffer[8]; // 8 bytes is the expected minimum size of the CID. + uint8_t Buffer[8]; TestScopeLogger LogScope1("GetParam test success case"); TEST_QUIC_STATUS( QUIC_STATUS_SUCCESS, @@ -4328,7 +4331,7 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { ) ) // - // There is no way the CID written should be 100 bytes. + // There is no way the CID written should be 100 bytes according to the RFC. // TEST_TRUE(SizeOfBuffer < 100); } From 2d96c0697284c2068a16614f7cf5bb000c0a507a Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 13 Jul 2023 12:23:48 -0700 Subject: [PATCH 06/11] no need to redefine client config --- src/test/lib/ApiTest.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/test/lib/ApiTest.cpp b/src/test/lib/ApiTest.cpp index e2e6495e01..e6f6a627b6 100644 --- a/src/test/lib/ApiTest.cpp +++ b/src/test/lib/ApiTest.cpp @@ -4228,7 +4228,7 @@ void QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(MsQuicRegistration& Registratio } -void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { +void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, MsQuicConfiguration& ClientConfiguration) { // // This is the unit test for checking to see if a server has the correct original dest CID. // @@ -4236,8 +4236,6 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { { MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); - MsQuicAlpn Alpn("MsQuicTest"); - MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); TEST_QUIC_SUCCEEDED( MsQuic->ConnectionStart( Connection.Handle, @@ -4263,8 +4261,6 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { { MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); - MsQuicAlpn Alpn("MsQuicTest"); - MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); TEST_QUIC_SUCCEEDED( MsQuic->ConnectionStart( Connection.Handle, @@ -4286,8 +4282,6 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { { MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); - MsQuicAlpn Alpn("MsQuicTest"); - MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); TEST_QUIC_SUCCEEDED( MsQuic->ConnectionStart( Connection.Handle, @@ -4310,8 +4304,6 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration) { { MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); - MsQuicAlpn Alpn("MsQuicTest"); - MsQuicConfiguration ClientConfiguration(Registration, Alpn, ClientCertCredConfig); TEST_QUIC_SUCCEEDED( MsQuic->ConnectionStart( Connection.Handle, @@ -4369,7 +4361,7 @@ void QuicTestConnectionParam() QuicTest_QUIC_PARAM_CONN_CIBIR_ID(Registration, ClientConfiguration); QuicTest_QUIC_PARAM_CONN_STATISTICS_V2(Registration); QuicTest_QUIC_PARAM_CONN_STATISTICS_V2_PLAT(Registration); - QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(Registration); + QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(Registration, ClientConfiguration); } // From 7d2763e7b71bf40c08ef8abec6daa5017b51aa27 Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 13 Jul 2023 14:00:18 -0700 Subject: [PATCH 07/11] add non-null checking --- src/core/connection.c | 2 +- src/test/lib/ApiTest.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/connection.c b/src/core/connection.c index 036290699d..556d0a35e3 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -7185,8 +7185,8 @@ QuicConnParamGet( break; } CxPlatCopyMemory( - Connection->OrigDestCID->Data, Buffer, + Connection->OrigDestCID->Data, Connection->OrigDestCID->Length); // // Tell app how much buffer we copied. diff --git a/src/test/lib/ApiTest.cpp b/src/test/lib/ApiTest.cpp index e6f6a627b6..0ecab54a5d 100644 --- a/src/test/lib/ApiTest.cpp +++ b/src/test/lib/ApiTest.cpp @@ -4243,11 +4243,13 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms QUIC_ADDRESS_FAMILY_INET, "localhost", 4433)); + MsQuic->ConnectionSetConfiguration(Connection.Handle, ClientConfiguration); // // 8 bytes is the expected minimum size of the CID. // uint32_t SizeOfBuffer = 8; - uint8_t Buffer[8]; + uint8_t Buffer[8] = {0}; + uint8_t ZeroBuffer[8] = {0}; TestScopeLogger LogScope1("GetParam test success case"); TEST_QUIC_STATUS( QUIC_STATUS_SUCCESS, @@ -4257,6 +4259,7 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms Buffer ) ) + TEST_NOT_EQUAL(memcmp(Buffer, ZeroBuffer, sizeof(Buffer)), 0); } { MsQuicConnection Connection(Registration); @@ -4313,6 +4316,7 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms 4433)); uint32_t SizeOfBuffer = 100; uint8_t Buffer[100]; + uint8_t ZeroBuffer[100] = {0}; TestScopeLogger LogScope1("GetParam size of buffer bigger than needed"); TEST_QUIC_STATUS( QUIC_STATUS_SUCCESS, @@ -4322,6 +4326,7 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms Buffer ) ) + TEST_NOT_EQUAL(memcmp(Buffer, ZeroBuffer, sizeof(Buffer)), 0); // // There is no way the CID written should be 100 bytes according to the RFC. // From 9e52c541b8b3b91ff1a8c593f2f93922f61ec752 Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 13 Jul 2023 14:21:05 -0700 Subject: [PATCH 08/11] fix formatting and use helpers --- src/core/connection.c | 8 +++---- src/test/lib/ApiTest.cpp | 46 ++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/core/connection.c b/src/core/connection.c index 556d0a35e3..5e60e126e5 100644 --- a/src/core/connection.c +++ b/src/core/connection.c @@ -7175,15 +7175,15 @@ QuicConnParamGet( Status = QUIC_STATUS_INVALID_STATE; break; } - if (Buffer == NULL) { - Status = QUIC_STATUS_INVALID_PARAMETER; - break; - } if (*BufferLength < Connection->OrigDestCID->Length) { Status = QUIC_STATUS_BUFFER_TOO_SMALL; *BufferLength = Connection->OrigDestCID->Length; break; } + if (Buffer == NULL) { + Status = QUIC_STATUS_INVALID_PARAMETER; + break; + } CxPlatCopyMemory( Buffer, Connection->OrigDestCID->Data, diff --git a/src/test/lib/ApiTest.cpp b/src/test/lib/ApiTest.cpp index 0ecab54a5d..90994d193d 100644 --- a/src/test/lib/ApiTest.cpp +++ b/src/test/lib/ApiTest.cpp @@ -4237,12 +4237,11 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); TEST_QUIC_SUCCEEDED( - MsQuic->ConnectionStart( - Connection.Handle, - ClientConfiguration, - QUIC_ADDRESS_FAMILY_INET, - "localhost", - 4433)); + Connection.Start( + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); MsQuic->ConnectionSetConfiguration(Connection.Handle, ClientConfiguration); // // 8 bytes is the expected minimum size of the CID. @@ -4265,12 +4264,11 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); TEST_QUIC_SUCCEEDED( - MsQuic->ConnectionStart( - Connection.Handle, - ClientConfiguration, - QUIC_ADDRESS_FAMILY_INET, - "localhost", - 4433)); + Connection.Start( + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); uint32_t SizeOfBuffer = 8; TestScopeLogger LogScope1("GetParam null buffer check"); TEST_QUIC_STATUS( @@ -4286,12 +4284,11 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); TEST_QUIC_SUCCEEDED( - MsQuic->ConnectionStart( - Connection.Handle, - ClientConfiguration, - QUIC_ADDRESS_FAMILY_INET, - "localhost", - 4433)); + Connection.Start( + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); uint32_t SizeOfBuffer = 1; TestScopeLogger LogScope1("GetParam buffer too small check"); uint8_t Buffer[1]; @@ -4308,14 +4305,13 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms MsQuicConnection Connection(Registration); TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); TEST_QUIC_SUCCEEDED( - MsQuic->ConnectionStart( - Connection.Handle, - ClientConfiguration, - QUIC_ADDRESS_FAMILY_INET, - "localhost", - 4433)); + Connection.Start( + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); uint32_t SizeOfBuffer = 100; - uint8_t Buffer[100]; + uint8_t Buffer[100] = {0}; uint8_t ZeroBuffer[100] = {0}; TestScopeLogger LogScope1("GetParam size of buffer bigger than needed"); TEST_QUIC_STATUS( From 7bb4d33097f9aed4d37c1a382e1f81395ed06dfa Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 13 Jul 2023 14:24:07 -0700 Subject: [PATCH 09/11] update description and add trailing whitespace --- docs/Settings.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/Settings.md b/docs/Settings.md index 9ab04d323d..36c0349f18 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -168,7 +168,8 @@ These parameters are accessed by calling [GetParam](./api/GetParam.md) or [SetPa | `QUIC_PARAM_CONN_CIBIR_ID`
21 | uint8_t[] | Set-only | The CIBIR well-known identifier. | | `QUIC_PARAM_CONN_STATISTICS_V2`
22 | QUIC_STATISTICS_V2 | Get-only | Connection-level statistics, version 2. | | `QUIC_PARAM_CONN_STATISTICS_V2_PLAT`
23 | QUIC_STATISTICS_V2 | Get-only | Connection-level statistics with platform-specific time format, version 2. | -| `QUIC_PARAM_CONN_ORIG_DEST_CID`
24 | uint8_t[] | Get-only | CID information about the original client that made the connection to the server. | +| `QUIC_PARAM_CONN_ORIG_DEST_CID`
24 | uint8_t[] | Get-only | The original destination connection ID used by the client to connect to the server. | + ### QUIC_PARAM_CONN_STATISTICS_V2 Querying the `QUIC_STATISTICS_V2` struct via `QUIC_PARAM_CONN_STATISTICS_V2` or `QUIC_PARAM_CONN_STATISTICS_V2_PLAT` should be aware of possible changes in the size of the struct, depending on the version of MsQuic the app using at runtime, not just what it was compiled against. From d7434f1570c72069663e466bbd526304d0d8a5be Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 13 Jul 2023 18:05:43 -0700 Subject: [PATCH 10/11] add null ptr queries --- src/test/lib/ApiTest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/lib/ApiTest.cpp b/src/test/lib/ApiTest.cpp index 90994d193d..7a28f9cf33 100644 --- a/src/test/lib/ApiTest.cpp +++ b/src/test/lib/ApiTest.cpp @@ -4328,6 +4328,35 @@ void QuicTest_QUIC_PARAM_CONN_ORIG_DEST_CID(MsQuicRegistration& Registration, Ms // TEST_TRUE(SizeOfBuffer < 100); } + { + MsQuicConnection Connection(Registration); + TEST_QUIC_SUCCEEDED(Connection.GetInitStatus()); + TEST_QUIC_SUCCEEDED( + Connection.Start( + ClientConfiguration, + QUIC_ADDRESS_FAMILY_INET, + "localhost", + 4433)); + uint32_t SizeOfBuffer = 0; + TestScopeLogger LogScope1("GetParam check OrigDestCID size with nullptr"); + TEST_QUIC_STATUS( + QUIC_STATUS_BUFFER_TOO_SMALL, + Connection.GetParam( + QUIC_PARAM_CONN_ORIG_DEST_CID, + &SizeOfBuffer, + nullptr + ) + ) + TEST_TRUE(SizeOfBuffer >= 8); + TEST_QUIC_STATUS( + QUIC_STATUS_INVALID_PARAMETER, + Connection.GetParam( + QUIC_PARAM_CONN_ORIG_DEST_CID, + &SizeOfBuffer, + nullptr + ) + ) + } } void QuicTestConnectionParam() From e21c9d884dbc0a52e6da599b4bd79ca60d4d869d Mon Sep 17 00:00:00 2001 From: Jack He Date: Fri, 14 Jul 2023 09:50:01 -0700 Subject: [PATCH 11/11] run ./scripts/generate-dotnet.ps1 --- src/cs/lib/msquic_generated.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cs/lib/msquic_generated.cs b/src/cs/lib/msquic_generated.cs index c9cc2c9255..5893eff899 100644 --- a/src/cs/lib/msquic_generated.cs +++ b/src/cs/lib/msquic_generated.cs @@ -3110,6 +3110,9 @@ internal static unsafe partial class MsQuic [NativeTypeName("#define QUIC_PARAM_CONN_STATISTICS_V2_PLAT 0x05000017")] internal const uint QUIC_PARAM_CONN_STATISTICS_V2_PLAT = 0x05000017; + [NativeTypeName("#define QUIC_PARAM_CONN_ORIG_DEST_CID 0x05000018")] + internal const uint QUIC_PARAM_CONN_ORIG_DEST_CID = 0x05000018; + [NativeTypeName("#define QUIC_PARAM_TLS_HANDSHAKE_INFO 0x06000000")] internal const uint QUIC_PARAM_TLS_HANDSHAKE_INFO = 0x06000000;