[PATCH 3/3] shell32/autocomplete: Revamp pwzsRegKeyPath handling so it can deal with arbitrary sizes and make it more robust

Alexandre Julliard julliard at winehq.org
Thu Aug 30 06:50:59 CDT 2018


Gabriel Ivăncescu <gabrielopcode at gmail.com> writes:

> On Thu, Aug 30, 2018 at 12:59 PM, Alexandre Julliard
> <julliard at winehq.org> wrote:
>> Gabriel Ivăncescu <gabrielopcode at gmail.com> writes:
>>
>>
>> This doesn't seem like an improvement. In particular, querying the key
>> twice just to retrieve the length is making things worse, and creating
>> more race conditions. Also note that RegQueryValueExW already adds a
>> terminating null if necessary.
>>
>> --
>> Alexandre Julliard
>> julliard at winehq.org
>
> Yes indeed the first query gets the length, but the second one makes
> sure the length is exactly the same so there can't be any race
> condition, unless I'm missing something?

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.

> About the NUL terminator: while it may be true for Wine's
> implementation, MSDN states that it's not necessarily the case (and
> tell you to use GetRegValue, which is more convoluted), and I imagine
> some application might hook RegQueryValueExW and provide a
> MSDN-compatible implementation or something (remote chance but it
> doesn't really hurt). Nevertheless, if you really think it's not an
> issue I will take that extra bit out then.

The Wine implementation replicates the Windows behavior, based on test
cases. That's more reliable than MSDN.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list