[ntdll] Fixed conditional expression (Coverity)

Paul Vriens Paul.Vriens at xs4all.nl
Mon Sep 18 06:55:25 CDT 2006


Hi,

'+' has precedence over '?'. The added test would crash our implementation.
The (very simple) test also shows that NULL input is allowed.

Fixes CID-640.

Changelog
  Fixed conditional expression

Cheers,

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

diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c
index e77c48a..bd32a3d 100644
--- a/dlls/ntdll/reg.c
+++ b/dlls/ntdll/reg.c
@@ -517,7 +517,7 @@ NTSTATUS WINAPI RtlpNtQueryValueKey( HAN
     UNICODE_STRING name;
     NTSTATUS ret;
     DWORD dwResultLen;
-    DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + result_len ? *result_len : 0;
+    DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + (result_len ? *result_len : 0);
 
     info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
     if (!info)
diff --git a/dlls/ntdll/tests/reg.c b/dlls/ntdll/tests/reg.c
index c9fab3a..252a815 100644
--- a/dlls/ntdll/tests/reg.c
+++ b/dlls/ntdll/tests/reg.c
@@ -103,6 +103,7 @@ static NTSTATUS (WINAPI * pRtlUnicodeStr
 static NTSTATUS (WINAPI * pRtlFreeHeap)(PVOID, ULONG, PVOID);
 static NTSTATUS (WINAPI * pRtlAllocateHeap)(PVOID,ULONG,ULONG);
 static NTSTATUS (WINAPI * pRtlZeroMemory)(PVOID, ULONG);
+static NTSTATUS (WINAPI * pRtlpNtQueryValueKey)(HANDLE,ULONG*,PBYTE,DWORD*);
 
 static HMODULE hntdll = 0;
 static int CurrentTest = 0;
@@ -146,6 +147,7 @@ static BOOL InitFunctionPtrs(void)
         NTDLL_GET_PROC(RtlFreeHeap)
         NTDLL_GET_PROC(RtlAllocateHeap)
         NTDLL_GET_PROC(RtlZeroMemory)
+        NTDLL_GET_PROC(RtlpNtQueryValueKey)
     }
     return TRUE;
 }
@@ -445,6 +447,14 @@ static void test_NtDeleteKey(void)
     ok(status == STATUS_SUCCESS, "NtDeleteKey Failed: 0x%08lx\n", status);
 }
 
+static void test_RtlpNtQueryValueKey(void)
+{
+    NTSTATUS status;
+
+    status = pRtlpNtQueryValueKey(NULL, NULL, NULL, NULL);
+    ok(status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got: 0x%08lx\n", status);
+}
+
 START_TEST(reg)
 {
     static const WCHAR winetest[] = {'\\','W','i','n','e','T','e','s','t','\\',0};
@@ -463,6 +473,7 @@ START_TEST(reg)
     test_RtlCheckRegistryKey();
     test_RtlOpenCurrentUser();
     test_RtlQueryRegistryValues();
+    test_RtlpNtQueryValueKey();
     test_NtFlushKey();
     test_NtDeleteKey();
 
-- 
1.4.2.1




More information about the wine-patches mailing list