Skip to content

Commit 423936a

Browse files
[release/6.0] Fixing regression for AuthType.Anonymous which leads to a NullReferenceException be thrown. (#62824)
* Fixing regression for AuthType.Anonymous which leads to a NullReferenceException be thrown. * Adding a unitTest to protect against a regression * Ensure System.DirectoryServices.Protocols package gets built. Co-authored-by: Jose Perez Rodriguez <joperezr@microsoft.com>
1 parent bbd29a6 commit 423936a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
44
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
55
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent);netcoreapp3.1-windows;netcoreapp3.1-OSX;netcoreapp3.1-Linux;netcoreapp3.1;netstandard2.0</TargetFrameworks>
66
<IsPackable>true</IsPackable>
77
<AddNETFrameworkPlaceholderFileToPackage>true</AddNETFrameworkPlaceholderFileToPackage>
88
<AddNETFrameworkAssemblyReferenceToPackage>true</AddNETFrameworkAssemblyReferenceToPackage>
9+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10+
<ServicingVersion>1</ServicingVersion>
911
<PackageDescription>Provides the methods defined in the Lightweight Directory Access Protocol (LDAP) version 3 (V3) and Directory Services Markup Language (DSML) version 2.0 (V2) standards.</PackageDescription>
1012
</PropertyGroup>
1113
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->

src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal static int BindToDirectory(ConnectionHandle ld, string who, string pass
111111
passwordPtr = LdapPal.StringToPtr(passwd);
112112
berval passwordBerval = new berval
113113
{
114-
bv_len = passwd.Length,
114+
bv_len = passwd?.Length ?? 0,
115115
bv_val = passwordPtr,
116116
};
117117

src/libraries/System.DirectoryServices.Protocols/tests/LdapConnectionTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ public void AuthType_SetValid_GetReturnsExpected()
112112
Assert.Equal(AuthType.Basic, connection.AuthType);
113113
}
114114

115+
[Fact]
116+
public void AuthType_Anonymous_DoesNotThrowNull()
117+
{
118+
var connection = new LdapConnection("server");
119+
connection.AuthType = AuthType.Anonymous;
120+
// When calling Bind we make sure that the exception thrown is not that there was a NullReferenceException
121+
// trying to retrive a null password's lenght, but instead an LdapException given the server cannot be reached.
122+
Assert.Throws<LdapException>(() => connection.Bind());
123+
}
124+
115125
[Theory]
116126
[InlineData(AuthType.Anonymous - 1)]
117127
[InlineData(AuthType.Kerberos + 1)]

0 commit comments

Comments
 (0)