From: Paul Gofman pgofman@codeweavers.com
--- dlls/ntdll/reg.c | 9 ++++++++- dlls/ntdll/tests/reg.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c index ccf83d59c28..33ad11f4c3b 100644 --- a/dlls/ntdll/reg.c +++ b/dlls/ntdll/reg.c @@ -312,11 +312,18 @@ static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo, res = 0; dst.MaximumLength = 0; RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res); - if (str->MaximumLength < res) + if (str->Buffer == NULL) + { + str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res); + str->MaximumLength = res; + } + else if (str->MaximumLength < res) return STATUS_BUFFER_TOO_SMALL; RtlExpandEnvironmentStrings_U(pEnvironment, &src, str, &res); + str->Length = (res >= sizeof(WCHAR) ? res - sizeof(WCHAR) : res); break; } + /* fallthrough */
case REG_SZ: case REG_LINK: diff --git a/dlls/ntdll/tests/reg.c b/dlls/ntdll/tests/reg.c index 2f008d3156d..0e191a125cc 100644 --- a/dlls/ntdll/tests/reg.c +++ b/dlls/ntdll/tests/reg.c @@ -2900,6 +2900,8 @@ static struct query_reg_values_test query_reg_values_tests[] =
static void test_RtlQueryRegistryValues(void) { + RTL_QUERY_REGISTRY_TABLE query_table[2]; + UNICODE_STRING str; NTSTATUS status; unsigned int i;
@@ -2923,6 +2925,20 @@ static void test_RtlQueryRegistryValues(void) L"Yellow", sizeof(L"Yellow")); ok(status == ERROR_SUCCESS, "Failed to create registry value Color: %lu\n", status);
+ RtlInitUnicodeString(&str, NULL); + memset(query_table, 0, sizeof(query_table)); + query_table[0].QueryRoutine = NULL; + query_table[0].Name = (WCHAR *)L"WindowsDrive"; + query_table[0].EntryContext = &str; + query_table[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_TYPECHECK; + query_table[0].DefaultType = REG_EXPAND_SZ << RTL_QUERY_REGISTRY_TYPECHECK_SHIFT; + status = pRtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE, winetestpath.Buffer, query_table, NULL, NULL); + ok(!status, "got %#lx.\n", status); + ok(!wcsicmp(str.Buffer, L"C:"), "got %s.\n", debugstr_w(str.Buffer)); + ok(str.Length == 4, "got %d.\n", str.Length); + ok(str.MaximumLength == 6, "got %d.\n", str.Length); + RtlFreeHeap(GetProcessHeap(), 0, str.Buffer); + for (i = 0; i < ARRAY_SIZE(query_reg_values_tests); i++) { struct query_reg_values_test *test = &query_reg_values_tests[i];
Fixes ntoskrnl.exe test failures introduced by ccb99cd00f55b716e3aa1a80ff4b13a6d6fa70d6.