Repository navigation
Conversation
Follow-up to 6694a42 Reported-by: Stanislav Fort
Member
Author
|
augment review |
There was a problem hiding this comment.
Pull request overview
This PR fixes a buffer handling issue in the IDN (Internationalized Domain Names) conversion code for Windows. The issue was that WideCharToMultiByte may not null-terminate the output string when a positive character count is provided, leading to potential buffer issues. The fix ensures proper buffer allocation and null-termination.
Key Changes:
- Allocates an extra byte for the null terminator in the UTF-8 buffer
- Captures the return value from
WideCharToMultiBytefor proper error checking and to determine where to place the null terminator - Adds comprehensive documentation explaining the behavior of
WideCharToMultiByteregarding null-termination
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bagder
marked this pull request as ready for review
December 15, 2025 07:10
vszakats
previously approved these changes
Dec 15, 2025
Member
vszakats
added a commit
to vszakats/curl
that referenced
this pull request
Dec 15, 2025
https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-idntoascii https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-idntounicode WINE source code: https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/kernelbase/locale.c https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/ntdll/locale.c https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/ntdll/locale_private.h Ref: curl#19976 (comment) Follow-up to 6694a42 curl#19798
Member
Author
|
Replaced by #19980 |
vszakats
added a commit
to vszakats/curl
that referenced
this pull request
Dec 16, 2025
Add comments to clarify that a terminating null is always present in the buffers returned to the caller. The curl APIs `win32_idn_to_ascii()` or `win32_ascii_to_idn()` receive a null-terminated UTF-8 string as input. They first convert it to wide chars by first asking `MultiByteToWideChar()` to calculate the length, by passing -1. This API returns the length with the null char included (= `strlen() + 1`), does the conversion, with the output also null-terminated. `IdnTo*()` preserve this null character as documented. Then we pass this null-terminated, fixed-length buffer ito `WideCharToMultiByte()`, which keeps preserving the null, ending up in the buffer returned to the caller. Refs: https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-idntoascii https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-idntounicode WINE source code: https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/kernelbase/locale.c https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/ntdll/locale.c https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/ntdll/locale_private.h Ref: curl#19976 (comment) Follow-up to 6694a42 curl#19798 Closes curl#19980
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.
Follow-up to 6694a42 #19798
Reported-by: Stanislav Fort