Draft
Fix LDAP referral callback host name marshaling#132227
Conversation
|
Azure Pipelines: 16 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (4)
src/libraries/System.DirectoryServices.Protocols/tests/ReferralCallbackTests.cs:70
- Same concern as the QueryForConnection marshaling test: this uses reflection over non-public members (including the private _ldapHandle field) and should be skipped on .NET Framework to avoid TFM-specific failures.
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void ProcessNotifyConnection_MarshalsHostNameAsAnsi()
src/libraries/System.DirectoryServices.Protocols/tests/ReferralCallbackTests.cs:45
- This test project multi-targets .NET Framework, but this test uses reflection over non-public implementation details (e.g., LdapSessionOptions.ProcessQueryConnection / LdapConnection._ldapHandle) that are not stable across TFMs. Other tests in this project explicitly skip .NET Framework for similar reflection-based access; this one should too to avoid NetFx-only failures.
This issue also appears on line 68 of the same file.
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void ProcessQueryConnection_MarshalsHostNameAsAnsi()
src/libraries/System.DirectoryServices.Protocols/tests/ReferralCallbackTests.cs:166
- AllocateAnsiString manually builds an ASCII buffer and double-null terminates it. Using Marshal.StringToHGlobalAnsi better matches the code under test (PtrToStringAnsi uses the active ANSI code page), reduces test-specific encoding assumptions, and simplifies the allocation logic.
private static IntPtr AllocateAnsiString(string value)
{
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(value);
IntPtr pointer = Marshal.AllocHGlobal(bytes.Length + 2);
Marshal.Copy(bytes, 0, pointer, bytes.Length);
src/libraries/System.DirectoryServices.Protocols/tests/ReferralCallbackTests.cs:169
- GetCallbackMethod currently returns null if the method name/signature changes, which then fails later as a NullReferenceException. Throwing a targeted exception here makes failures easier to diagnose (especially given this is reflection over a private method).
private static MethodInfo GetCallbackMethod(string name) =>
typeof(LdapSessionOptions).GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic);
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
Copilot
AI
changed the title
[WIP] Fix LdapConnection marshal HostName for ReferralCallback
Fix LDAP referral callback host name marshaling
Aug 12, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-directoryservices |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
main PR
Description
Referral callbacks decoded the native
PCHAR HostNameas UTF-16, producing garbled referral server identifiers.HostNamewithMarshal.PtrToStringAnsiin both query and notify callback paths.NewDN.Customer Impact
Referral callback consumers receive the correct referred server identifier when chasing referrals.
Regression
Behavior differs from .NET Framework; this corrects the Windows callback marshaling mismatch.
Testing
Focused callback marshaling coverage for query and notify callbacks.
Risk
Low. The change aligns pointer decoding with the documented Windows LDAP callback ABI.
Package authoring no longer needed in .NET 9
IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.