Skip to content

Commit f4be095

Browse files
kwy404zpostfacto
authored andcommitted
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.
1 parent 7441f73 commit f4be095

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,8 +2220,9 @@ bool CSteamNetworkingUtils::SetConfigValue( ESteamNetworkingConfigValue eValue,
22202220
case k_ESteamNetworkingConfig_ConnectionUserData:
22212221
{
22222222

2223-
// We only need special handling when modifying a connection
2224-
if ( eScopeType != k_ESteamNetworkingConfig_Connection )
2223+
// We only need special handling when modifying a connection.
2224+
// Clearing it (NULL) falls through and is rejected by SetConfigValueTyped.
2225+
if ( eScopeType != k_ESteamNetworkingConfig_Connection || pValue == nullptr )
22252226
break;
22262227

22272228
// Process the user argument, maybe performing type conversion

‎tests/test_connection.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,9 @@ void Test_pipe()
12271227
assert( infoBob.m_identityRemote == identAlice );
12281228
}
12291229

1230+
// Connection user data cannot be cleared. Passing NULL should fail, not crash.
1231+
assert( !SteamNetworkingUtils()->SetConfigValue( k_ESteamNetworkingConfig_ConnectionUserData, k_ESteamNetworkingConfig_Connection, hAlice, k_ESteamNetworkingConfig_Int64, nullptr ) );
1232+
12301233
// Wire up to the global peer state used by TestNetworkConditions / PumpCallbacksAndMakeSureStillConnected.
12311234
g_peerClient.Reset();
12321235
g_peerServer.Reset();

0 commit comments

Comments
 (0)