[ntdll][2/3] Fix returncodes for NtOpenKey (with tests)

Paul Vriens Paul.Vriens at xs4all.nl
Mon Jul 3 07:19:54 CDT 2006


Hi,

New tests pass on NT4/W2K/XP/W2K3 and Wine.

Some original tests still fail for NT4, haven't looked into that (yet).

Changelog
  Fix returncodes for NtOpenKey (with tests) 

Cheers,

Paul.
---
 dlls/ntdll/reg.c       |   11 +++++++----
 dlls/ntdll/tests/reg.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c
index c88bc1f..fb67207 100644
--- a/dlls/ntdll/reg.c
+++ b/dlls/ntdll/reg.c
@@ -116,13 +116,16 @@ NTSTATUS WINAPI RtlpNtCreateKey( PHANDLE
 NTSTATUS WINAPI NtOpenKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
 {
     NTSTATUS ret;
-    DWORD len = attr->ObjectName->Length;
+    DWORD len;
 
-    TRACE( "(%p,%s,%lx,%p)\n", attr->RootDirectory,
-           debugstr_us(attr->ObjectName), access, retkey );
+    TRACE( "(%p,%s,%lx,%p)\n", (attr) ? attr->RootDirectory : NULL,
+           (attr) ? debugstr_us(attr->ObjectName) : NULL, access, retkey );
 
+    if (!retkey || !attr) return STATUS_ACCESS_VIOLATION;
+    if (attr->Length > sizeof(OBJECT_ATTRIBUTES)) return STATUS_INVALID_PARAMETER;
+
+    len = attr->ObjectName->Length;
     if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
-    if (!retkey) return STATUS_INVALID_PARAMETER;
 
     SERVER_START_REQ( open_key )
     {
diff --git a/dlls/ntdll/tests/reg.c b/dlls/ntdll/tests/reg.c
index 654ae64..6f04b23 100644
--- a/dlls/ntdll/tests/reg.c
+++ b/dlls/ntdll/tests/reg.c
@@ -290,6 +290,34 @@ static void test_RtlQueryRegistryValues(
     pRtlFreeHeap(GetProcessHeap(), 0, QueryTable);
 }
 
+static void test_NtOpenKey(void)
+{
+    HANDLE key;
+    NTSTATUS status;
+    OBJECT_ATTRIBUTES attr;
+    ACCESS_MASK am = KEY_READ;
+
+    /* All NULL */
+    status = pNtOpenKey(NULL, 0, NULL);
+    ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got: 0x%08lx\n", status);
+
+    /* NULL attributes */
+    status = pNtOpenKey(&key, 0, NULL);
+    ok(status == STATUS_ACCESS_VIOLATION /* W2K3/XP/W2K */ || status == STATUS_INVALID_PARAMETER /* NT4 */,
+        "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER(NT4), got: 0x%08lx\n", status);
+
+    InitializeObjectAttributes(&attr, &winetestpath, 0, 0, 0);
+
+    /* NULL key */
+    status = pNtOpenKey(NULL, 0, &attr);
+    ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got: 0x%08lx\n", status);
+
+    /* Length > sizeof(OBJECT_ATTRIBUTES) */
+    attr.Length *= 2;
+    status = pNtOpenKey(&key, am, &attr);
+    ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got: 0x%08lx\n", status);
+}
+
 static void test_NtCreateKey(void)
 {
     /*Create WineTest*/
@@ -401,6 +429,7 @@ START_TEST(reg)
 
     pRtlAppendUnicodeToString(&winetestpath, winetest);
 
+    test_NtOpenKey();
     test_NtCreateKey();
     test_NtSetValueKey();
     test_RtlCheckRegistryKey();
-- 
1.4.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winehq.org/pipermail/wine-patches/attachments/20060703/1074d886/attachment.htm


More information about the wine-patches mailing list