From: Rose Hellsing <rose@pinkro.se> Add tests for NtCreatePort error paths including NULL/zero-length object attributes, NULL/empty port names, duplicate port names, and invalid maximum message/connect info sizes --- dlls/ntdll/tests/port.c | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/dlls/ntdll/tests/port.c b/dlls/ntdll/tests/port.c index 6dc8da6bf87..c2ad1eddb46 100644 --- a/dlls/ntdll/tests/port.c +++ b/dlls/ntdll/tests/port.c @@ -333,6 +333,88 @@ static void test_ports_server( HANDLE PortHandle ) HeapFree(GetProcessHeap(), 0, LpcMessage); } +static void test_create_port_errors(void) +{ + OBJECT_ATTRIBUTES obj; + HANDLE port_handle; + NTSTATUS status; + UNICODE_STRING name; + static const WCHAR ERR_PORT1[] = {'\\','E','r','r','P','o','r','t','1',0}; + static const WCHAR ERR_PORT2[] = {'\\','E','r','r','P','o','r','t','2',0}; + static const WCHAR ERR_PORT3[] = {'\\','E','r','r','P','o','r','t','3',0}; + + /* NULL object attributes */ + status = pNtCreatePort(&port_handle, NULL, 0, 0, 0); + ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER || status == STATUS_ACCESS_VIOLATION, + "Expected STATUS_SUCCESS, STATUS_INVALID_PARAMETER or STATUS_ACCESS_VIOLATION, got %08lx\n", status); + if (status == STATUS_SUCCESS) NtClose(port_handle); + + /* Zero-length object attributes */ + memset(&obj, 0, sizeof(OBJECT_ATTRIBUTES)); + obj.Length = 0; + status = pNtCreatePort(&port_handle, &obj, 0, 0, 0); + ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER || status == STATUS_INVALID_HANDLE, + "Expected STATUS_SUCCESS, STATUS_INVALID_PARAMETER or STATUS_INVALID_HANDLE, got %08lx\n", status); + if (status == STATUS_SUCCESS) NtClose(port_handle); + + /* Valid object attributes but NULL name */ + memset(&obj, 0, sizeof(OBJECT_ATTRIBUTES)); + obj.Length = sizeof(OBJECT_ATTRIBUTES); + obj.ObjectName = NULL; + status = pNtCreatePort(&port_handle, &obj, 0, 0, 0); + ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER || status == STATUS_OBJECT_NAME_INVALID, + "Expected STATUS_SUCCESS, STATUS_INVALID_PARAMETER or STATUS_OBJECT_NAME_INVALID, got %08lx\n", status); + if (status == STATUS_SUCCESS) NtClose(port_handle); + + /* Empty name */ + pRtlInitUnicodeString(&name, L""); + memset(&obj, 0, sizeof(OBJECT_ATTRIBUTES)); + obj.Length = sizeof(OBJECT_ATTRIBUTES); + obj.ObjectName = &name; + status = pNtCreatePort(&port_handle, &obj, 0, 0, 0); + ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER || status == STATUS_OBJECT_NAME_INVALID, + "Expected STATUS_SUCCESS, STATUS_INVALID_PARAMETER or STATUS_OBJECT_NAME_INVALID, got %08lx\n", status); + if (status == STATUS_SUCCESS) NtClose(port_handle); + + /* Max message size too large */ + pRtlInitUnicodeString(&name, ERR_PORT1); + memset(&obj, 0, sizeof(OBJECT_ATTRIBUTES)); + obj.Length = sizeof(OBJECT_ATTRIBUTES); + obj.ObjectName = &name; + status = pNtCreatePort(&port_handle, &obj, 0x100001, 0, 0); + ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER || status == STATUS_SECTION_TOO_BIG || status == STATUS_OBJECT_NAME_COLLISION, + "Expected STATUS_SUCCESS, STATUS_INVALID_PARAMETER, STATUS_SECTION_TOO_BIG or STATUS_OBJECT_NAME_COLLISION, got %08lx\n", status); + if (status == STATUS_SUCCESS) NtClose(port_handle); + + /* Max connect info too large */ + pRtlInitUnicodeString(&name, ERR_PORT2); + memset(&obj, 0, sizeof(OBJECT_ATTRIBUTES)); + obj.Length = sizeof(OBJECT_ATTRIBUTES); + obj.ObjectName = &name; + status = pNtCreatePort(&port_handle, &obj, 0, 0x100001, 0); + ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER || status == STATUS_SECTION_TOO_BIG || status == STATUS_OBJECT_NAME_COLLISION, + "Expected STATUS_SUCCESS, STATUS_INVALID_PARAMETER, STATUS_SECTION_TOO_BIG or STATUS_OBJECT_NAME_COLLISION, got %08lx\n", status); + if (status == STATUS_SUCCESS) NtClose(port_handle); + + /* Creating port with name that already exists */ + pRtlInitUnicodeString(&name, ERR_PORT3); + memset(&obj, 0, sizeof(OBJECT_ATTRIBUTES)); + obj.Length = sizeof(OBJECT_ATTRIBUTES); + obj.ObjectName = &name; + status = pNtCreatePort(&port_handle, &obj, 100, 100, 0); + ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status); + if (status == STATUS_SUCCESS) + { + NTSTATUS status2; + HANDLE port_handle2; + status2 = pNtCreatePort(&port_handle2, &obj, 100, 100, 0); + ok(status2 == STATUS_OBJECT_NAME_COLLISION, + "Expected STATUS_OBJECT_NAME_COLLISION, got %08lx\n", status2); + NtClose(port_handle); + } +} + + START_TEST(port) { OBJECT_ATTRIBUTES obj; @@ -374,5 +456,7 @@ START_TEST(port) ok( WaitForSingleObject( thread, 10000 ) == 0, "thread didn't exit\n" ); CloseHandle(thread); } + test_create_port_errors(); + FreeLibrary(hntdll); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11243