Skip to content

Fixing regression for AuthType.Anonymous which leads to a NullReferenceException be thrown. #62807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal static int BindToDirectory(ConnectionHandle ld, string who, string pass
passwordPtr = LdapPal.StringToPtr(passwd);
BerVal passwordBerval = new BerVal
{
bv_len = passwd.Length,
bv_len = passwd?.Length ?? 0,
bv_val = passwordPtr,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ public void AuthType_SetValid_GetReturnsExpected()
Assert.Equal(AuthType.Basic, connection.AuthType);
}

[Fact]
public void AuthType_Anonymous_DoesNotThrowNull()
{
var connection = new LdapConnection("server");
connection.AuthType = AuthType.Anonymous;
// When calling Bind we make sure that the exception thrown is not that there was a NullReferenceException
// trying to retrive a null password's lenght, but instead an LdapException given the server cannot be reached.
Assert.Throws<LdapException>(() => connection.Bind());
}

[Theory]
[InlineData(AuthType.Anonymous - 1)]
[InlineData(AuthType.Kerberos + 1)]
Expand Down