From 21b2dc96e52bea754ba1a416e5b857ce0d34f460 Mon Sep 17 00:00:00 2001 From: kwy404 Date: Fri, 25 Sep 2026 17:32:57 -0300 Subject: [PATCH] SetConfigValue: Don't crash when clearing connection user data Passing NULL to SetConfigValue for k_ESteamNetworkingConfig_ConnectionUserData at connection scope took the user data special case, which converted the value with AssignConfigValueTyped() and dereferenced the NULL pointer. The check in SetConfigValueTyped() that rejects clearing connection user data was never reached. Let NULL fall through to SetConfigValueTyped(), so the call fails with "Cannot clear connection user data" instead of crashing, and add a check for it to the pipe test. --- .../clientlib/csteamnetworkingsockets.cpp | 5 +++-- tests/test_connection.cpp | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp b/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp index 02918d2a..998fac80 100644 --- a/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp +++ b/src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp @@ -2220,8 +2220,9 @@ bool CSteamNetworkingUtils::SetConfigValue( ESteamNetworkingConfigValue eValue, case k_ESteamNetworkingConfig_ConnectionUserData: { - // We only need special handling when modifying a connection - if ( eScopeType != k_ESteamNetworkingConfig_Connection ) + // We only need special handling when modifying a connection. + // Clearing it (NULL) falls through and is rejected by SetConfigValueTyped. + if ( eScopeType != k_ESteamNetworkingConfig_Connection || pValue == nullptr ) break; // Process the user argument, maybe performing type conversion diff --git a/tests/test_connection.cpp b/tests/test_connection.cpp index 22d50378..44284160 100644 --- a/tests/test_connection.cpp +++ b/tests/test_connection.cpp @@ -1227,6 +1227,9 @@ void Test_pipe() assert( infoBob.m_identityRemote == identAlice ); } + // Connection user data cannot be cleared. Passing NULL should fail, not crash. + assert( !SteamNetworkingUtils()->SetConfigValue( k_ESteamNetworkingConfig_ConnectionUserData, k_ESteamNetworkingConfig_Connection, hAlice, k_ESteamNetworkingConfig_Int64, nullptr ) ); + // Wire up to the global peer state used by TestNetworkConditions / PumpCallbacksAndMakeSureStillConnected. g_peerClient.Reset(); g_peerServer.Reset();