Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSparin <sparin285@gmail.com>2022-09-27 18:33:33 +0300
committerGitHub <noreply@github.com>2022-09-27 18:33:33 +0300
commit94c6fe6cf5667967f6cf0ebc5c381501b8363b9b (patch)
tree8804da626efeeab3b8bb43ff4c7100e446e24db3 /src/libraries
parent36bd4286032ac5d1c3e9b95ec31558fbb1c70902 (diff)
Fix incorrect string length calculation (#76127)
ANSI string depends on system encoding charset. Unix's implementation of Marshal.StringToHGlobalAnsi encodes in UTF8. UTF8 characters which are out of 8-bit range (otcet) encodes in multiple bytes (otcets). ASCII characters usually are in 0x00-0x7F range but cyrillic and other characters are not. For example, 'Зфыы123;' (eq. 'Pass123$') will be encoded in 12 bytes instead of 8 Fix #76125
Diffstat (limited to 'src/libraries')
-rw-r--r--src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs4
1 files changed, 2 insertions, 2 deletions
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 c751636ac85..e2fd327a91f 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
@@ -120,7 +120,7 @@ namespace System.DirectoryServices.Protocols
// This option is not supported in Linux, so it would most likely throw.
internal static int SetServerCertOption(ConnectionHandle ldapHandle, LdapOption option, VERIFYSERVERCERT outValue) => Interop.Ldap.ldap_set_option_servercert(ldapHandle, option, outValue);
- internal static int BindToDirectory(ConnectionHandle ld, string who, string passwd)
+ internal static unsafe int BindToDirectory(ConnectionHandle ld, string who, string passwd)
{
IntPtr passwordPtr = IntPtr.Zero;
try
@@ -128,7 +128,7 @@ namespace System.DirectoryServices.Protocols
passwordPtr = LdapPal.StringToPtr(passwd);
BerVal passwordBerval = new BerVal
{
- bv_len = passwd?.Length ?? 0,
+ bv_len = MemoryMarshal.CreateReadOnlySpanFromNullTerminated((byte*)passwordPtr).Length,
bv_val = passwordPtr,
};