From 58edf0b679e124e1d07881ae9c263af072ff1c83 Mon Sep 17 00:00:00 2001 From: Giannis Adamopoulos Date: Thu, 17 Aug 2017 14:37:24 +0000 Subject: [PATCH] [ADVAPI32] -RegOpenKeyExW: Call NtOpenKey again with aligned parameters if STATUS_DATATYPE_MISALIGNMENT was returned the first time. CORE-13689 svn path=/trunk/; revision=75592 --- reactos/dll/win32/advapi32/reg/reg.c | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/reactos/dll/win32/advapi32/reg/reg.c b/reactos/dll/win32/advapi32/reg/reg.c index 8fe9e36e9a0..42d00a33905 100644 --- a/reactos/dll/win32/advapi32/reg/reg.c +++ b/reactos/dll/win32/advapi32/reg/reg.c @@ -3429,6 +3429,39 @@ RegOpenKeyExW(HKEY hKey, samDesired, &ObjectAttributes); + if (Status == STATUS_DATATYPE_MISALIGNMENT) + { + HANDLE hAligned; + UNICODE_STRING AlignedString; + + Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, + &SubKeyString, + &AlignedString); + if (NT_SUCCESS(Status)) + { + /* Try again with aligned parameters */ + InitializeObjectAttributes(&ObjectAttributes, + &AlignedString, + Attributes, + KeyHandle, + NULL); + + Status = NtOpenKey(&hAligned, + samDesired, + &ObjectAttributes); + + RtlFreeUnicodeString(&AlignedString); + + if (NT_SUCCESS(Status)) + *phkResult = hAligned; + } + else + { + /* Restore the original error */ + Status = STATUS_DATATYPE_MISALIGNMENT; + } + } + if (!NT_SUCCESS(Status)) { ErrorCode = RtlNtStatusToDosError(Status);