From: Sven Baars sbaars@codeweavers.com
--- dlls/kernelbase/registry.c | 51 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/dlls/kernelbase/registry.c b/dlls/kernelbase/registry.c index 0137cbe6cad..0f629ab2d36 100644 --- a/dlls/kernelbase/registry.c +++ b/dlls/kernelbase/registry.c @@ -100,7 +100,8 @@ static inline BOOL is_version_nt(void)
static BOOL is_wow6432node( const UNICODE_STRING *name ) { - return (name->Length == 11 * sizeof(WCHAR) && !wcsnicmp( name->Buffer, L"Wow6432Node", 11 )); + DWORD len = name->Length / sizeof(WCHAR); + return (len >= 11 && !wcsnicmp( name->Buffer, L"Wow6432Node\", min( len, 12 ) )); }
/* open the Wow6432Node subkey of the specified key */ @@ -220,7 +221,7 @@ static NTSTATUS open_key( HKEY *retkey, DWORD options, ACCESS_MASK access, OBJEC BOOL force_wow32 = is_win64 && (access & KEY_WOW64_32KEY); HANDLE subkey, root = attr->RootDirectory; WCHAR *buffer = attr->ObjectName->Buffer; - DWORD pos = 0, i = 0, len = attr->ObjectName->Length / sizeof(WCHAR); + DWORD i, len = attr->ObjectName->Length / sizeof(WCHAR); UNICODE_STRING str;
*retkey = NULL; @@ -237,24 +238,17 @@ static NTSTATUS open_key( HKEY *retkey, DWORD options, ACCESS_MASK access, OBJEC return status; }
- if (len && buffer[0] == '\') return STATUS_OBJECT_PATH_INVALID; - while (i < len && buffer[i] != '\') i++; attr->ObjectName = &str;
- for (;;) + while (len) { - str.Buffer = buffer + pos; - str.Length = (i - pos) * sizeof(WCHAR); - if (force_wow32 && pos) - { - if (is_wow6432node( &str )) force_wow32 = FALSE; - else if ((subkey = open_wow6432node( attr->RootDirectory ))) - { - if (attr->RootDirectory != root) NtClose( attr->RootDirectory ); - attr->RootDirectory = subkey; - force_wow32 = FALSE; - } - } + i = 0; + if (buffer[0] == '\') return STATUS_OBJECT_PATH_INVALID; + while (i < len && buffer[i] != '\') i++; + + str.Buffer = buffer; + str.Length = i * sizeof(WCHAR); + if (i == len) { if (options & REG_OPTION_OPEN_LINK) attr->Attributes |= OBJ_OPENLINK; @@ -268,15 +262,22 @@ static NTSTATUS open_key( HKEY *retkey, DWORD options, ACCESS_MASK access, OBJEC if (attr->RootDirectory != root) NtClose( attr->RootDirectory ); if (status) return status; attr->RootDirectory = subkey; - if (i == len) break; while (i < len && buffer[i] == '\') i++; - pos = i; - while (i < len && buffer[i] != '\') i++; - } - if (force_wow32 && (subkey = open_wow6432node( attr->RootDirectory ))) - { - if (attr->RootDirectory != root) NtClose( attr->RootDirectory ); - attr->RootDirectory = subkey; + buffer += i; + len -= i; + + if (force_wow32) + { + str.Buffer = buffer; + str.Length = len * sizeof(WCHAR); + if (is_wow6432node( &str )) force_wow32 = FALSE; + else if ((subkey = open_wow6432node( attr->RootDirectory ))) + { + NtClose( attr->RootDirectory ); + attr->RootDirectory = subkey; + force_wow32 = FALSE; + } + } } if (status == STATUS_PREDEFINED_HANDLE) {