On Wed, 12 Aug 2026 17:19:18 GMT, Mat Carter <[email protected]> wrote:

>> @macarte afaik you are from Microsoft, is this true? Can you or someone else 
>> from MS comment on the RegOpenKeyExA  / RegCloseKey topic ?
>
> @MBaesken - yes, if the subKey is non-null and not empty then you have to 
> close the key to free the handle.  GetCodePageSubkey does appear to return 
> only NULL or not empty, perhaps maybe add an assert to make sure and document 
> that we should not return empty strings here; otherwise if it is non-null but 
> empty, then it is indeed a shared key and should not be closed.
> 
> Two points:
> 
> 1) As we're only reading the value, consider using KEY_QUERY_VALUE or 
> KEY_READ (stricter) instead of KEY_ALL_ACCESS; see: 
> https://learn.microsoft.com/en-us/windows/win32/sysinfo/registry-key-security-and-access-rights
> 
> 2) While you are potentially reading two values, using RegGetValueA (avoiding 
> explicit open/close calls) could simplify the code and remove the chance of 
> handle leaks with future code changes.

Hi @macarte thanks for the clarification and the useful additional info, very 
helpful !

@prrace should I switch to  KEY_READ as suggested ?
Here it is done too
https://github.com/openjdk/jdk/blob/d426d66b5e27f54f676f04e3263eb72be67b1f5f/src/java.base/windows/native/libnet/ResolverConfigurationImpl.c#L166-L169

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

PR Comment: https://git.openjdk.org/jdk/pull/32249#issuecomment-5277505444

Reply via email to