Module: wine Branch: master Commit: 500be1e8db1b081900fd1ce9802265bc831d1c8a URL: http://source.winehq.org/git/wine.git/?a=commit;h=500be1e8db1b081900fd1ce980...
Author: Francois Gouget fgouget@codeweavers.com Date: Tue Nov 18 21:58:04 2008 +0100
ntdll/tests: Test how NT(Set, Query)ValueKey() handle non-terminated strings.
---
dlls/ntdll/tests/reg.c | 29 +++++++++++++++++++++++++++-- 1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/tests/reg.c b/dlls/ntdll/tests/reg.c index 7b4a9ed..23dd278 100644 --- a/dlls/ntdll/tests/reg.c +++ b/dlls/ntdll/tests/reg.c @@ -29,6 +29,11 @@ #include "winnls.h" #include "stdlib.h"
+/* A test string */ +static const WCHAR stringW[] = {'s', 't', 'r', 'i', 'n', 'g', 'W', 0}; +/* A size, in bytes, short enough to cause truncation of the above */ +#define STR_TRUNC_SIZE (sizeof(stringW)-2*sizeof(*stringW)) + #ifndef __WINE_WINTERNL_H
/* RtlQueryRegistryValues structs and defines */ @@ -413,16 +418,20 @@ static void test_NtSetValueKey(void) UNICODE_STRING ValName; DWORD data = 711;
- pRtlCreateUnicodeStringFromAsciiz(&ValName, "deletetest"); - InitializeObjectAttributes(&attr, &winetestpath, 0, 0, 0); status = pNtOpenKey(&key, am, &attr); ok(status == STATUS_SUCCESS, "NtOpenKey Failed: 0x%08x\n", status);
+ pRtlCreateUnicodeStringFromAsciiz(&ValName, "deletetest"); status = pNtSetValueKey(key, &ValName, 0, REG_DWORD, &data, sizeof(data)); ok(status == STATUS_SUCCESS, "NtSetValueKey Failed: 0x%08x\n", status); + pRtlFreeUnicodeString(&ValName);
+ pRtlCreateUnicodeStringFromAsciiz(&ValName, "stringtest"); + status = pNtSetValueKey(key, &ValName, 0, REG_SZ, (VOID*)stringW, STR_TRUNC_SIZE); + ok(status == STATUS_SUCCESS, "NtSetValueKey Failed: 0x%08x\n", status); pRtlFreeUnicodeString(&ValName); + pNtClose(key); }
@@ -545,6 +554,22 @@ static void test_NtQueryValueKey(void) HeapFree(GetProcessHeap(), 0, full_info);
pRtlFreeUnicodeString(&ValName); + pRtlCreateUnicodeStringFromAsciiz(&ValName, "stringtest"); + + status = pNtQueryValueKey(key, &ValName, KeyValuePartialInformation, NULL, 0, &len); + todo_wine ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryValueKey should have returned STATUS_BUFFER_TOO_SMALL instead of 0x%08x\n", status); + partial_info = HeapAlloc(GetProcessHeap(), 0, len+1); + memset((BYTE*)partial_info, 0xbd, len+1); + status = pNtQueryValueKey(key, &ValName, KeyValuePartialInformation, partial_info, len, &len); + ok(status == STATUS_SUCCESS, "NtQueryValueKey should have returned STATUS_SUCCESS instead of 0x%08x\n", status); + ok(partial_info->TitleIndex == 0, "NtQueryValueKey returned wrong TitleIndex %d\n", partial_info->TitleIndex); + ok(partial_info->Type == REG_SZ, "NtQueryValueKey returned wrong Type %d\n", partial_info->Type); + ok(partial_info->DataLength == STR_TRUNC_SIZE, "NtQueryValueKey returned wrong DataLength %d\n", partial_info->DataLength); + ok(!memcmp(partial_info->Data, stringW, STR_TRUNC_SIZE), "incorrect Data returned\n"); + ok(*(partial_info->Data+STR_TRUNC_SIZE) == 0xbd, "string overflowed %02x\n", *(partial_info->Data+STR_TRUNC_SIZE)); + HeapFree(GetProcessHeap(), 0, partial_info); + + pRtlFreeUnicodeString(&ValName); pNtClose(key); }