Alexandre Julliard : kernel32: Add a helper function to fill object attributes in Open* functions.

Alexandre Julliard julliard at winehq.org
Fri Mar 2 12:16:44 CST 2018


Module: wine
Branch: master
Commit: a7aa192a78d02d28f2bbae919a3f5c726e4e9e60
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=a7aa192a78d02d28f2bbae919a3f5c726e4e9e60

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Mar  2 10:40:41 2018 +0100

kernel32: Add a helper function to fill object attributes in Open* functions.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/sync.c       | 79 +++++++++++-----------------------------------
 dlls/kernel32/tests/sync.c | 40 +++++++++++++++++++++++
 2 files changed, 59 insertions(+), 60 deletions(-)

diff --git a/dlls/kernel32/sync.c b/dlls/kernel32/sync.c
index d3d46b7..fbe5c3b 100644
--- a/dlls/kernel32/sync.c
+++ b/dlls/kernel32/sync.c
@@ -81,6 +81,20 @@ HANDLE get_BaseNamedObjects_handle(void)
     return handle;
 }
 
+static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
+                                        BOOL inherit, const WCHAR *name )
+{
+    if (!name)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+    RtlInitUnicodeString( nameW, name );
+    InitializeObjectAttributes( attr, nameW, inherit ? OBJ_INHERIT : 0,
+                                get_BaseNamedObjects_handle(), NULL );
+    return TRUE;
+}
+
 /* helper for kernel32->ntdll timeout format conversion */
 static inline PLARGE_INTEGER get_nt_timeout( PLARGE_INTEGER pTime, DWORD timeout )
 {
@@ -530,18 +544,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW( DWORD access, BOOL inherit, LPCWSTR
 
     if (!is_version_nt()) access = EVENT_ALL_ACCESS;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = inherit ? OBJ_INHERIT : 0;
-    attr.SecurityDescriptor       = NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
 
     status = NtOpenEvent( &ret, access, &attr );
     if (status != STATUS_SUCCESS)
@@ -692,18 +695,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexW( DWORD access, BOOL inherit, LPCWSTR
 
     if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = inherit ? OBJ_INHERIT : 0;
-    attr.SecurityDescriptor       = NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
 
     status = NtOpenMutant( &ret, access, &attr );
     if (status != STATUS_SUCCESS)
@@ -837,18 +829,7 @@ HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreW( DWORD access, BOOL inherit, LPCW
 
     if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = inherit ? OBJ_INHERIT : 0;
-    attr.SecurityDescriptor       = NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
 
     status = NtOpenSemaphore( &ret, access, &attr );
     if (status != STATUS_SUCCESS)
@@ -933,18 +914,7 @@ HANDLE WINAPI OpenJobObjectW( DWORD access, BOOL inherit, LPCWSTR name )
     OBJECT_ATTRIBUTES attr;
     NTSTATUS status;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = inherit ? OBJ_INHERIT : 0;
-    attr.SecurityDescriptor       = NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
 
     status = NtOpenJobObject( &ret, access, &attr );
     if (status != STATUS_SUCCESS)
@@ -1140,18 +1110,7 @@ HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
 
     if (!is_version_nt()) access = TIMER_ALL_ACCESS;
 
-    attr.Length                   = sizeof(attr);
-    attr.RootDirectory            = 0;
-    attr.ObjectName               = NULL;
-    attr.Attributes               = inherit ? OBJ_INHERIT : 0;
-    attr.SecurityDescriptor       = NULL;
-    attr.SecurityQualityOfService = NULL;
-    if (name)
-    {
-        RtlInitUnicodeString( &nameW, name );
-        attr.ObjectName = &nameW;
-        attr.RootDirectory = get_BaseNamedObjects_handle();
-    }
+    if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
 
     status = NtOpenTimer(&handle, access, &attr);
     if (status != STATUS_SUCCESS)
diff --git a/dlls/kernel32/tests/sync.c b/dlls/kernel32/tests/sync.c
index 83ab534..f7be51e 100644
--- a/dlls/kernel32/tests/sync.c
+++ b/dlls/kernel32/tests/sync.c
@@ -265,6 +265,16 @@ todo_wine
     ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
 
     SetLastError(0xdeadbeef);
+    hOpened = OpenMutexA(READ_CONTROL, FALSE, NULL);
+    ok(!hOpened, "OpenMutex succeeded\n");
+    ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    hOpened = OpenMutexW(READ_CONTROL, FALSE, NULL);
+    ok(!hOpened, "OpenMutex succeeded\n");
+    ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
     hOpened = CreateMutexA(NULL, FALSE, "WineTestMutex");
     ok(hOpened != NULL, "CreateMutex failed with error %d\n", GetLastError());
     ok(GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
@@ -517,6 +527,16 @@ static void test_event(void)
     ok( !handle2, "OpenEvent succeeded\n");
     ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
 
+    SetLastError(0xdeadbeef);
+    handle2 = OpenEventA( EVENT_ALL_ACCESS, FALSE, NULL );
+    ok( !handle2, "OpenEvent succeeded\n");
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    handle2 = OpenEventW( EVENT_ALL_ACCESS, FALSE, NULL );
+    ok( !handle2, "OpenEvent succeeded\n");
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
     CloseHandle( handle );
 
     /* resource notifications are events too */
@@ -586,6 +606,16 @@ static void test_semaphore(void)
     ok( !handle2, "OpenSemaphore succeeded\n");
     ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
 
+    SetLastError(0xdeadbeef);
+    handle2 = OpenSemaphoreA( SEMAPHORE_ALL_ACCESS, FALSE, NULL );
+    ok( !handle2, "OpenSemaphore succeeded\n");
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    handle2 = OpenSemaphoreW( SEMAPHORE_ALL_ACCESS, FALSE, NULL );
+    ok( !handle2, "OpenSemaphore succeeded\n");
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
     CloseHandle( handle );
 }
 
@@ -622,6 +652,16 @@ static void test_waitable_timer(void)
     ok( !handle2, "OpenWaitableTimer succeeded\n");
     ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
 
+    SetLastError(0xdeadbeef);
+    handle2 = OpenWaitableTimerA( TIMER_ALL_ACCESS, FALSE, NULL );
+    ok( !handle2, "OpenWaitableTimer failed with error %d\n", GetLastError());
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+    SetLastError(0xdeadbeef);
+    handle2 = OpenWaitableTimerW( TIMER_ALL_ACCESS, FALSE, NULL );
+    ok( !handle2, "OpenWaitableTimer failed with error %d\n", GetLastError());
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
     CloseHandle( handle );
 }
 




More information about the wine-cvs mailing list