From 97645d7a1a9eec6100c637534620ac6811622794 Mon Sep 17 00:00:00 2001 From: Ken Thomases Date: Mon, 12 Mar 2012 22:50:09 -0500 Subject: [PATCH] ntdll: Fix status returned for too-long registry value names. --- dlls/ntdll/reg.c | 6 +++--- dlls/ntdll/tests/reg.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c index d68f1543aa8..cdca88aee97 100644 --- a/dlls/ntdll/reg.c +++ b/dlls/ntdll/reg.c @@ -190,7 +190,7 @@ NTSTATUS WINAPI NtDeleteValueKey( HANDLE hkey, const UNICODE_STRING *name ) NTSTATUS ret; TRACE( "(%p,%s)\n", hkey, debugstr_us(name) ); - if (name->Length > MAX_VALUE_LENGTH) return STATUS_BUFFER_OVERFLOW; + if (name->Length > MAX_VALUE_LENGTH) return STATUS_OBJECT_NAME_NOT_FOUND; SERVER_START_REQ( delete_key_value ) { @@ -483,7 +483,7 @@ NTSTATUS WINAPI NtQueryValueKey( HANDLE handle, const UNICODE_STRING *name, TRACE( "(%p,%s,%d,%p,%d)\n", handle, debugstr_us(name), info_class, info, length ); - if (name->Length > MAX_VALUE_LENGTH) return STATUS_BUFFER_OVERFLOW; + if (name->Length > MAX_VALUE_LENGTH) return STATUS_OBJECT_NAME_NOT_FOUND; /* compute the length we want to retrieve */ switch(info_class) @@ -771,7 +771,7 @@ NTSTATUS WINAPI NtSetValueKey( HANDLE hkey, const UNICODE_STRING *name, ULONG Ti TRACE( "(%p,%s,%d,%p,%d)\n", hkey, debugstr_us(name), type, data, count ); - if (name->Length > MAX_VALUE_LENGTH) return STATUS_BUFFER_OVERFLOW; + if (name->Length > MAX_VALUE_LENGTH) return STATUS_INVALID_PARAMETER; SERVER_START_REQ( set_key_value ) { diff --git a/dlls/ntdll/tests/reg.c b/dlls/ntdll/tests/reg.c index 1bd0a017af9..d56d4f8001f 100644 --- a/dlls/ntdll/tests/reg.c +++ b/dlls/ntdll/tests/reg.c @@ -1244,6 +1244,41 @@ static void test_redirection(void) pNtClose( key64 ); } +static void test_long_value_name(void) +{ + HANDLE key; + NTSTATUS status, expected; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING ValName; + DWORD i; + + InitializeObjectAttributes(&attr, &winetestpath, 0, 0, 0); + status = pNtOpenKey(&key, KEY_WRITE|KEY_READ, &attr); + ok(status == STATUS_SUCCESS, "NtOpenKey Failed: 0x%08x\n", status); + + ValName.MaximumLength = 0xfffc; + ValName.Length = ValName.MaximumLength - sizeof(WCHAR); + ValName.Buffer = HeapAlloc(GetProcessHeap(), 0, ValName.MaximumLength); + for (i = 0; i < ValName.Length / sizeof(WCHAR); i++) + ValName.Buffer[i] = 'a'; + ValName.Buffer[i] = 0; + + status = pNtDeleteValueKey(key, &ValName); + ok(status == STATUS_OBJECT_NAME_NOT_FOUND, "NtDeleteValueKey with nonexistent long value name returned 0x%08x\n", status); + status = pNtSetValueKey(key, &ValName, 0, REG_DWORD, &i, sizeof(i)); + ok(status == STATUS_INVALID_PARAMETER || broken(status == STATUS_SUCCESS) /* nt4 */, + "NtSetValueKey with long value name returned 0x%08x\n", status); + expected = (status == STATUS_SUCCESS) ? STATUS_SUCCESS : STATUS_OBJECT_NAME_NOT_FOUND; + status = pNtDeleteValueKey(key, &ValName); + ok(status == expected, "NtDeleteValueKey with long value name returned 0x%08x\n", status); + + status = pNtQueryValueKey(key, &ValName, KeyValueBasicInformation, NULL, 0, &i); + ok(status == STATUS_OBJECT_NAME_NOT_FOUND, "NtQueryValueKey with nonexistent long value name returned 0x%08x\n", status); + + pRtlFreeUnicodeString(&ValName); + pNtClose(key); +} + START_TEST(reg) { static const WCHAR winetest[] = {'\\','W','i','n','e','T','e','s','t',0}; @@ -1265,6 +1300,7 @@ START_TEST(reg) test_RtlpNtQueryValueKey(); test_NtFlushKey(); test_NtQueryValueKey(); + test_long_value_name(); test_NtDeleteKey(); test_symlinks(); test_redirection();