Skip to content

Commit 9f9808d

Browse files
committed
(PUP-10943) Puppet read registry until WCHAR_NULL
On Windows, it is possible to have a registry that contains corrupted data after the WCHAR_NULL characters, that can break puppet when reading the registy. Part of the fix was done in PUP-10536, but when the WCHAR_NULL from the registry is \u0000 instead of \u0000\u0000, the split did not work. Now WCHAR_NULL is forced encoded to UTF-16LE, meaning `\u000` so puppet will now stop at the WCHAR_NULL char. The initial issue can be reproduced by importing file.reg using `reg import .\file.reg` ----file.reg---- Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PUP105360000] "DisplayName"="PUP105" "DisplayVersion"=hex(2):32,0,0,0,f3,23,8a,bc,fa,7f,0,0,10,65,74,b9,fa,7f,0,0,90,d8,55,6f,59
1 parent 12401c3 commit 9f9808d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/puppet/ffi/windows/api_types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def attach_function_private(*args)
2020

2121
class ::FFI::Pointer
2222
NULL_HANDLE = 0
23-
WCHAR_NULL = "\0\0".encode('UTF-16LE').freeze
23+
WCHAR_NULL = "\0\0".force_encoding('UTF-16LE').freeze
2424

2525
def self.from_string_to_wide_string(str, &block)
2626
str = Puppet::Util::Windows::String.wide_string(str)

spec/integration/util/windows/registry_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ def write_corrupt_dword(reg, valuename)
263263
type: Win32::Registry::REG_EXPAND_SZ,
264264
value: "\0\0\0reg expand string",
265265
expected_value: ""
266+
},
267+
{
268+
name: 'REG_EXPAND_SZ_2',
269+
type: Win32::Registry::REG_EXPAND_SZ,
270+
value: "1\x002\x003\x004\x00\x00\x00\x90\xD8UoY".force_encoding("UTF-16LE"),
271+
expected_value: "1234"
266272
}
267273
].each do |pair|
268274
it 'reads up to the first wide null' do

0 commit comments

Comments
 (0)