Skip to content

Use the native timeval layout for LDAP timeouts on Unix - #136587

Merged
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-ldap-timeval-native-layout
Oct 28, 2026
Merged

EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-ldap-timeval-native-layout

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 28, 2026

Copy link
Copy Markdown
Member

LDAP_TIMEVAL was declared with two 32-bit ints, which is the Windows LDAP_TIMEVAL (LONG fields). The same struct is passed by reference to OpenLDAP (ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT), ldap_result, ldap_search_ext), which expects a struct timeval of time_t/suseconds_t, i.e. two C longs (16 bytes on LP64). OpenLDAP therefore read 8 bytes past the managed struct and interpreted tv_sec and tv_usec of the managed value together as its 64-bit tv_sec. As a result LdapConnection.Timeout was not honored (a connection attempt to an unreachable host only failed after the OS TCP timeout) and a search time limit was only correct by accident.

Declare the fields as CLong, which is a 32-bit LONG on Windows (unchanged layout) and a 64-bit long on LP64 Unix, matching both native definitions with a single type.

LDAP_TIMEVAL was declared with two 32-bit ints, which is the Windows LDAP_TIMEVAL (LONG fields). The same struct is passed by reference to OpenLDAP (ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT), ldap_result, ldap_search_ext), which expects a struct timeval of time_t/suseconds_t, i.e. two C longs (16 bytes on LP64). OpenLDAP therefore read 8 bytes past the managed struct and interpreted tv_sec and tv_usec of the managed value together as its 64-bit tv_sec. As a result LdapConnection.Timeout was not honored (a connection attempt to an unreachable host only failed after the OS TCP timeout) and a search time limit was only correct by accident.

Declare the fields as CLong, which is a 32-bit LONG on Windows (unchanged layout) and a 64-bit long on LP64 Unix, matching both native definitions with a single type.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a13c23e0-b8e7-47bd-9714-cdc27528b527
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-directoryservices
See info in area-owners.md if you want to be subscribed.

EgorBo and others added 2 commits October 28, 2026 17:43
Co-authored-by: Copilot <[email protected]>
Copilot-Session: f86ef291-922b-46a2-bed8-98845b7c4e0e
Co-authored-by: Copilot <[email protected]>
Copilot-Session: f86ef291-922b-46a2-bed8-98845b7c4e0e
@EgorBo

EgorBo commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

Not sure who ask a review for, perhaps @jkoritzinsky?

@EgorBo
EgorBo requested a review from jkoritzinsky October 28, 2026 18:15
@EgorBo
EgorBo merged commit a9e5f22 into dotnet:main Oct 28, 2026
88 checks passed
@EgorBo
EgorBo deleted the fix-ldap-timeval-native-layout branch October 28, 2026 23:51
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants