Skip to content

Commit bdaad42

Browse files
authored
Fix AcquireCredentialHandle parameter lifetime (#113540)
* Fix lifetime of data passed to native code during SslStream handshake on Windows. * Remove unnecessary init * Fix init
1 parent acc910a commit bdaad42

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/libraries/System.Net.Security/src/System/Net/Security/SslStreamPal.Windows.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,11 @@ public static unsafe SafeFreeCredentials AcquireCredentialsHandleSchannelCred(Ss
353353
secureCredential.dwSessionLifespan = -1;
354354
}
355355

356+
Interop.Crypt32.CERT_CONTEXT* certificateHandle;
356357
if (certificate != null)
357358
{
358359
secureCredential.cCreds = 1;
359-
Interop.Crypt32.CERT_CONTEXT* certificateHandle = (Interop.Crypt32.CERT_CONTEXT*)certificate.Handle;
360+
certificateHandle = (Interop.Crypt32.CERT_CONTEXT*)certificate.Handle;
360361
secureCredential.paCred = &certificateHandle;
361362
}
362363

@@ -434,19 +435,21 @@ public static unsafe SafeFreeCredentials AcquireCredentialsHandleSchCredentials(
434435
credential.dwSessionLifespan = -1;
435436
}
436437

438+
Interop.Crypt32.CERT_CONTEXT* certificateHandle;
437439
if (certificate != null)
438440
{
439441
credential.cCreds = 1;
440-
Interop.Crypt32.CERT_CONTEXT* certificateHandle = (Interop.Crypt32.CERT_CONTEXT*)certificate.Handle;
442+
certificateHandle = (Interop.Crypt32.CERT_CONTEXT*)certificate.Handle;
441443
credential.paCred = &certificateHandle;
442444
}
443445

444446
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info($"flags=({flags}), ProtocolFlags=({protocolFlags}), EncryptionPolicy={policy}");
445447

448+
Interop.SspiCli.TLS_PARAMETERS tlsParameters;
446449
if (protocolFlags != 0)
447450
{
448451
// If we were asked to do specific protocol we need to fill TLS_PARAMETERS.
449-
Interop.SspiCli.TLS_PARAMETERS tlsParameters = default;
452+
tlsParameters = default;
450453
tlsParameters.grbitDisabledProtocols = (uint)protocolFlags ^ uint.MaxValue;
451454

452455
credential.cTlsParameters = 1;

0 commit comments

Comments
 (0)