Skip to content

winldap: avoid NULL pointer deref on ldap_get_dn() fail#22000

Closed
vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:ldapfail
Closed

winldap: avoid NULL pointer deref on ldap_get_dn() fail#22000
vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:ldapfail

Conversation

@vszakats

@vszakats vszakats commented Jun 14, 2026

Copy link
Copy Markdown
Member

In non-Unicode builds.

Assisted-by: Jay Satiro


https://github.com/curl/curl/pull/22000/files?w=1

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the WinLDAP code path in lib/ldap.c by preventing a NULL pointer from being passed into the curlx_convert_tchar_to_UTF8() conversion when ldap_get_dn() fails (notably affecting non-Unicode builds where the conversion maps to curlx_strdup()), and aligns formatting with surrounding code style.

Changes:

  • Add a NULL check around the WinLDAP ldap_get_dn() return value before attempting TCHAR→UTF-8 conversion.
  • Preserve existing error handling flow for “no DN available” (CURLE_FAILED_INIT) while avoiding a crash.
  • Minor whitespace cleanup (removes extra blank lines).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/ldap.c Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread lib/ldap.c Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@vszakats vszakats requested a review from jay June 15, 2026 10:30

@jay jay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref: MicrosoftDocs/sdk-api#2222

MS documentation has incorrect return type PCHAR (char *) for many ldap functions. In fact they are closer to PTCHAR (wchar_t * if UNICODE, char * if not), so AFAICT we are as close as we can be to correct here.

@vszakats vszakats closed this in 46ba384 Jun 15, 2026
@vszakats vszakats deleted the ldapfail branch June 15, 2026 16:39
@vszakats

Copy link
Copy Markdown
Member Author

Thanks @jay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LDAP Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

3 participants