On Thu, 5 Nov 2026 18:58:06 GMT, Alan Bateman <[email protected]> wrote:

>> Thanks for the explanation. It makes sense.
>> 
>> I find it hard to see what cause the error condition. Maybe it's better to 
>> change the comment to
>> 
>> 
>> } else {
>>   // Either of the above GetFinalPathNameByHandleW() calls has failed
>>   ...
>
> Here's an alternative that avoids the else branch. This should handle the 
> potential for the final path length to change between the two calls.
> 
> -        if (len >= size) {
> -            if ((finalPath = (WCHAR*)malloc(len * sizeof(WCHAR))) == NULL)
> +        if (len != 0 && len >= size) {
> +            DWORD pathBufferSize = len;
> +            finalPath = (WCHAR*)malloc((size_t)pathBufferSize * 
> sizeof(WCHAR));
> +            if (finalPath == NULL) {
> +                CloseHandle(h);
>                  return NULL;
> -            len = GetFinalPathNameByHandleW(h, finalPath, len, 0);
> +            }
> +            len = GetFinalPathNameByHandleW(h, finalPath, pathBufferSize, 0);
> +            if (len == 0 || len >= pathBufferSize) {
> +                CloseHandle(h);
> +                free(finalPath);
> +                return NULL;
> +            }

Hi Alan, thanks for the suggestions!
I added them.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/33752#discussion_r4490355076

Reply via email to