You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RegQueryValueExW doesn't guarantee the returned buffer for the `lpData`
parameter is null terminated, so ensure that it is.
When retrieving a registry value of type REG_SZ or REG_EXPAND_SZ extend the
buffer by 1 wchar (2 bytes) so we can always write a wchar null terminator that
is guaranteed not to overwrite user data.
The resulting wchar array is then guaranteed to be properly wchar null
terminated:
\u0041
\u0042
\u0000
which when UTF-16LE encoded will result in the byte array:
\x41 \x00
\x42 \x00
\x00 \x00
If Windows does null terminate, then we will add an additional wchar null
terminator, which won't hurt anything.
The same applies to REG_MULTI_SZ, except it is supposed to have two wchar null
terminators, for a total of 4 bytes. One terminator is for the last string in
the array, and one terminator is for the entire array. For example, if the array
contains the strings ['A', 'B'] and Windows does not null terminate the
`lpData` buffer, then the resulting UTF-16LE encoded byte array will contain:
\x41 \x00
\x00 \x00
\x42 \x00
\x00 \x00
\x00 \x00
0 commit comments