From fe202ffab3705b87cf27ed69f863deb0322bc2c7 Mon Sep 17 00:00:00 2001 From: Jose Perez Rodriguez Date: Tue, 14 Dec 2021 10:56:16 -0800 Subject: [PATCH 1/3] Fixing regression for AuthType.Anonymous which leads to a NullReferenceException be thrown. --- .../System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs index d67782f40ad36b..a2619871edecb4 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs @@ -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, }; From 3502a179aa3e294040aebc013eb917eda6bc84f4 Mon Sep 17 00:00:00 2001 From: Jose Perez Rodriguez Date: Tue, 14 Dec 2021 12:28:42 -0800 Subject: [PATCH 2/3] Adding a unitTest to protect against a regression --- .../tests/LdapConnectionTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libraries/System.DirectoryServices.Protocols/tests/LdapConnectionTests.cs b/src/libraries/System.DirectoryServices.Protocols/tests/LdapConnectionTests.cs index 9a8074bf5222ad..a0522a61abc182 100644 --- a/src/libraries/System.DirectoryServices.Protocols/tests/LdapConnectionTests.cs +++ b/src/libraries/System.DirectoryServices.Protocols/tests/LdapConnectionTests.cs @@ -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(() => connection.Bind()); + } + [Theory] [InlineData(AuthType.Anonymous - 1)] [InlineData(AuthType.Kerberos + 1)] From a4ca9220c4bfa0d5e2d64525979f7d92e3f71890 Mon Sep 17 00:00:00 2001 From: Jose Perez Rodriguez Date: Tue, 14 Dec 2021 16:52:58 -0800 Subject: [PATCH 3/3] Ensure System.DirectoryServices.Protocols package gets built. --- .../src/System.DirectoryServices.Protocols.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj b/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj index d9839c121271df..8c4836e5ff6649 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj +++ b/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj @@ -1,4 +1,4 @@ - + true true @@ -6,6 +6,8 @@ true true true + true + 1 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.