From a75f5b63753bf0b1f8cc0ea2bf5f195de297fef6 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 11 Jun 2011 11:58:46 +0000 Subject: [PATCH] [NTOSKRNL] - Do not create/open the CurrentVersion key in a single call to NtCreateKey because its parent key might not exist yet. See issue #6302 for more details. svn path=/trunk/; revision=52184 --- reactos/ntoskrnl/config/cmsysini.c | 95 ++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/reactos/ntoskrnl/config/cmsysini.c b/reactos/ntoskrnl/config/cmsysini.c index f6b3142a68b..8159383ecbf 100644 --- a/reactos/ntoskrnl/config/cmsysini.c +++ b/reactos/ntoskrnl/config/cmsysini.c @@ -1946,13 +1946,16 @@ CmpSetVersionData(VOID) UNICODE_STRING KeyName; UNICODE_STRING ValueName; UNICODE_STRING ValueData; - HANDLE KeyHandle; + HANDLE SoftwareKeyHandle = NULL; + HANDLE MicrosoftKeyHandle = NULL; + HANDLE WindowsNtKeyHandle = NULL; + HANDLE CurrentVersionKeyHandle = NULL; WCHAR Buffer[128]; NTSTATUS Status; /* Open the 'CurrentVersion' key */ RtlInitUnicodeString(&KeyName, - L"\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"); + L"\\REGISTRY\\MACHINE\\SOFTWARE"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, @@ -1960,7 +1963,7 @@ CmpSetVersionData(VOID) NULL, NULL); - Status = NtCreateKey(&KeyHandle, + Status = NtCreateKey(&SoftwareKeyHandle, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, @@ -1973,6 +1976,75 @@ CmpSetVersionData(VOID) return; } + /* Open the 'CurrentVersion' key */ + RtlInitUnicodeString(&KeyName, + L"Microsoft"); + + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + SoftwareKeyHandle, + NULL); + + Status = NtCreateKey(&MicrosoftKeyHandle, + KEY_CREATE_SUB_KEY, + &ObjectAttributes, + 0, + NULL, + 0, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status); + goto done; + } + + /* Open the 'CurrentVersion' key */ + RtlInitUnicodeString(&KeyName, + L"Windows NT"); + + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + MicrosoftKeyHandle, + NULL); + + Status = NtCreateKey(&WindowsNtKeyHandle, + KEY_CREATE_SUB_KEY, + &ObjectAttributes, + 0, + NULL, + 0, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status); + goto done; + } + + /* Open the 'CurrentVersion' key */ + RtlInitUnicodeString(&KeyName, + L"CurrentVersion"); + + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + WindowsNtKeyHandle, + NULL); + + Status = NtCreateKey(&CurrentVersionKeyHandle, + KEY_CREATE_SUB_KEY | KEY_SET_VALUE, + &ObjectAttributes, + 0, + NULL, + 0, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status); + goto done; + } + /* Set the 'CurrentType' value */ RtlInitUnicodeString(&ValueName, L"CurrentType"); @@ -1994,15 +2066,26 @@ CmpSetVersionData(VOID) RtlInitUnicodeString(&ValueData, Buffer); - NtSetValueKey(KeyHandle, + NtSetValueKey(CurrentVersionKeyHandle, &ValueName, 0, REG_SZ, ValueData.Buffer, ValueData.Length + sizeof(WCHAR)); - /* Close the key */ - NtClose(KeyHandle); +done:; + /* Close the keys */ + if (CurrentVersionKeyHandle != NULL) + NtClose(CurrentVersionKeyHandle); + + if (WindowsNtKeyHandle != NULL) + NtClose(WindowsNtKeyHandle); + + if (MicrosoftKeyHandle != NULL) + NtClose(MicrosoftKeyHandle); + + if (SoftwareKeyHandle != NULL) + NtClose(SoftwareKeyHandle); } /* EOF */