Skip to content

Commit 1f67139

Browse files
authored
CSHARP-4797: Fix segfault when disposing of GSSAPI (Kerberos) security context on Linux. (#1256)
1 parent b213cef commit 1f67139

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/MongoDB.Driver.Core/Core/Authentication/Libgssapi/GssapiSecurityContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public byte[] EncryptMessage(byte[] plainTextBytes)
6363

6464
protected override bool ReleaseHandle()
6565
{
66-
var majorStatus = NativeMethods.gss_delete_sec_context(out var minorStatus, handle, IntPtr.Zero);
66+
var majorStatus = NativeMethods.gss_delete_sec_context(out var minorStatus, ref handle, IntPtr.Zero);
6767
return majorStatus == 0 && minorStatus == 0;
6868
}
6969

src/MongoDB.Driver.Core/Core/Authentication/Libgssapi/NativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal static class NativeMethods
5353
public static extern uint gss_release_cred(out uint minorStatus, IntPtr credentialHandle);
5454

5555
[DllImport(GSSAPI_LIBRARY)]
56-
public static extern uint gss_delete_sec_context(out uint minorStatus, IntPtr securityContextHandle, IntPtr outputToken);
56+
public static extern uint gss_delete_sec_context(out uint minorStatus, ref IntPtr securityContextHandle, IntPtr outputToken);
5757

5858
[DllImport(GSSAPI_LIBRARY)]
5959
public static extern uint gss_wrap(out uint minorStatus, IntPtr securityContextHandle, int confidentialityRequested, int protectionType, GssInputBuffer inputBuffer, out int confidentialityState, [MarshalAs(UnmanagedType.LPStruct)] GssOutputBuffer outputBuffer);

tests/MongoDB.Driver.Core.Tests/Core/Authentication/Libgssapi/GssapiSecurityCredentialTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void Should_acquire_gssapi_security_credential_with_username_and_password
4646
RequireEnvironment.Check().EnvironmentVariable("GSSAPI_TESTS_ENABLED");
4747

4848
var securePassword = SecureStringHelper.ToSecureString(_password);
49-
var credential = GssapiSecurityCredential.Acquire(_username, securePassword);
49+
using var credential = GssapiSecurityCredential.Acquire(_username, securePassword);
5050
credential.Should().NotBeNull();
5151
}
5252

@@ -55,7 +55,7 @@ public void Should_acquire_gssapi_security_credential_with_username_only()
5555
{
5656
RequireEnvironment.Check().EnvironmentVariable("GSSAPI_TESTS_ENABLED");
5757

58-
var credential = GssapiSecurityCredential.Acquire(_username);
58+
using var credential = GssapiSecurityCredential.Acquire(_username);
5959
credential.Should().NotBeNull();
6060
}
6161

0 commit comments

Comments
 (0)