diff --git a/.gitignore b/.gitignore index 91567f0013..ed3ba3518b 100644 --- a/.gitignore +++ b/.gitignore @@ -388,4 +388,7 @@ _site APKBUILD # Temporary package download folder by validation script -msquic-packages/ \ No newline at end of file +msquic-packages/ +# CodeQL build artifacts +_codeql_build_dir/ +_codeql_detected_source_root diff --git a/src/core/cubic.c b/src/core/cubic.c index a685c9486f..86ccbb3b0f 100644 --- a/src/core/cubic.c +++ b/src/core/cubic.c @@ -430,7 +430,8 @@ CubicCongestionControlGetNetworkStatistics( NetworkStatistics->IdealBytes = Connection->SendBuffer.IdealBytes; NetworkStatistics->SmoothedRTT = Path->SmoothedRtt; NetworkStatistics->CongestionWindow = Cubic->CongestionWindow; - NetworkStatistics->Bandwidth = Cubic->CongestionWindow / Path->SmoothedRtt; + NetworkStatistics->Bandwidth = + Path->SmoothedRtt == 0 ? 0 : Cubic->CongestionWindow / Path->SmoothedRtt; } _IRQL_requires_max_(DISPATCH_LEVEL) diff --git a/src/core/unittest/CubicTest.cpp b/src/core/unittest/CubicTest.cpp index ade9028d6d..456aca0ebc 100644 --- a/src/core/unittest/CubicTest.cpp +++ b/src/core/unittest/CubicTest.cpp @@ -769,3 +769,33 @@ TEST(CubicTest, HyStart_StateTransitions) Cubic->HyStartState <= HYSTART_DONE); ASSERT_GE(Cubic->CWndSlowStartGrowthDivisor, 1u); } + +// +// Test 18: GetNetworkStatistics - Zero RTT Graceful Handling +// Scenario: Verifies that GetNetworkStatistics does not divide by zero when +// SmoothedRtt is 0 (before the first RTT sample is received). It should +// return Bandwidth=0 instead of crashing. +// +TEST(CubicTest, GetNetworkStatistics_ZeroRtt) +{ + QUIC_CONNECTION Connection; + QUIC_SETTINGS_INTERNAL Settings{}; + Settings.InitialWindowPackets = 10; + Settings.SendIdleTimeoutMs = 1000; + + InitializeMockConnection(Connection, 1280); + // SmoothedRtt is 0 by default (no RTT sample received yet) + + CubicCongestionControlInitialize(&Connection.CongestionControl, &Settings); + + QUIC_NETWORK_STATISTICS NetworkStats; + CxPlatZeroMemory(&NetworkStats, sizeof(NetworkStats)); + + Connection.CongestionControl.QuicCongestionControlGetNetworkStatistics( + &Connection, + &Connection.CongestionControl, + &NetworkStats); + + // Bandwidth should be 0 when SmoothedRtt is 0 (graceful degradation) + ASSERT_EQ(NetworkStats.Bandwidth, 0u); +}