On Thu, Aug 30, 2018 at 2:50 PM, Alexandre Julliard julliard@winehq.org wrote:
Gabriel Ivăncescu gabrielopcode@gmail.com writes:
There can still be a race, only you are making the function fail in that case, that's not nice behavior. The right way to do that sort of thing is to allocate a reasonable buffer, get the string (without querying the length first), and on overflow restart the loop with a larger buffer.
Okay, you are right. I'll have it get the length first (because this simplifies the case where the value doesn't exist in HKCU but it does in HKLM), and start with that buffer size, then use a loop until it returns success (or some error other than ERROR_MORE_DATA) or its type is not REG_SZ (this should be a failure, right?).
The Wine implementation replicates the Windows behavior, based on test cases. That's more reliable than MSDN.
Yes you are correct but some hooks (like madCodeHook used in jauntePE) might hook the registry APIs to provide virtualized redirections. They *might* follow the MSDN instead of test-cases, because that's what MSDN claims, I really have no idea if they'll return a non-NUL terminated string though. Was just playing it safe. At the very least, should I just forcefully NUL terminate the buffer? (without increasing its size by +1) It would only be a single extra store and doesn't do anything on an already NUL terminated buffer.