Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PUP-11122) Ensure reg values are null terminated
RegQueryValueExW doesn't guarantee the returned buffer for the `lpcbData` 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 `lpcbData` buffer, then the resulting UTF-16LE encoded byte array will contain: \x41 \x00 \x00 \x00 \x42 \x00 \x00 \x00 \x00 \x00
- Loading branch information