diff --git a/dlls/ws2_32/async.c b/dlls/ws2_32/async.c index cc330bbd077..573349fe92e 100644 --- a/dlls/ws2_32/async.c +++ b/dlls/ws2_32/async.c @@ -384,7 +384,7 @@ HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, { struct async_query_getservbyname *aq; unsigned int len1 = strlen(name) + 1; - unsigned int len2 = strlen(proto) + 1; + unsigned int len2 = proto ? strlen(proto) + 1 : 0; TRACE("hwnd %p, msg %04x, name %s, proto %s\n", hWnd, uMsg, debugstr_a(name), debugstr_a(proto)); @@ -393,10 +393,18 @@ HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, SetLastError( WSAEWOULDBLOCK ); return 0; } + aq->serv_name = (char *)(aq + 1); - aq->serv_proto = aq->serv_name + len1; strcpy( aq->serv_name, name ); - strcpy( aq->serv_proto, proto ); + + if (proto) + { + aq->serv_proto = aq->serv_name + len1; + strcpy( aq->serv_proto, proto ); + } + else + aq->serv_proto = NULL; + return run_query( hWnd, uMsg, async_getservbyname, &aq->query, sbuf, buflen ); } diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 2de23c96471..f4cc909ec1e 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -5203,6 +5203,33 @@ static void test_WSAAsyncGetServByPort(void) DestroyWindow(hwnd); } +static void test_WSAAsyncGetServByName(void) +{ + HWND hwnd = create_async_message_window(); + HANDLE ret; + char buffer[MAXGETHOSTSTRUCT]; + + if (!hwnd) + return; + + /* FIXME: The asynchronous window messages should be tested. */ + + /* Parameters are not checked when initiating the asynchronous operation. */ + ret = WSAAsyncGetServByName(hwnd, WM_ASYNCCOMPLETE, "", NULL, NULL, 0); + ok(ret != NULL, "WSAAsyncGetServByName returned NULL\n"); + + ret = WSAAsyncGetServByName(hwnd, WM_ASYNCCOMPLETE, "", "", buffer, MAXGETHOSTSTRUCT); + ok(ret != NULL, "WSAAsyncGetServByName returned NULL\n"); + + ret = WSAAsyncGetServByName(hwnd, WM_ASYNCCOMPLETE, "http", NULL, NULL, 0); + ok(ret != NULL, "WSAAsyncGetServByName returned NULL\n"); + + ret = WSAAsyncGetServByName(hwnd, WM_ASYNCCOMPLETE, "http", "tcp", buffer, MAXGETHOSTSTRUCT); + ok(ret != NULL, "WSAAsyncGetServByName returned NULL\n"); + + DestroyWindow(hwnd); +} + static void test_completion_port(void) { HANDLE previous_port, io_port; @@ -5770,6 +5797,7 @@ START_TEST( sock ) test_sioRoutingInterfaceQuery(); test_WSAAsyncGetServByPort(); + test_WSAAsyncGetServByName(); test_completion_port();