-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PUP-11122) Ensure reg values are null terminated #9205
Conversation
e681e19
to
a8fc33d
Compare
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
This should be backported in 7.x |
If Windows does correctly terminate the string and we add extra padding, then I wanted to verify it wouldn't cause issues, for example, when converting the
|
Successfully created backport PR for |
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:
which when UTF-16LE encoded will result in the byte array:
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: