ws2_32: Avoid a crash with an optional pointer in WSAAsyncGetServByPort.

This commit is contained in:
Andrew Nguyen 2011-06-01 07:14:18 -05:00 committed by Alexandre Julliard
parent 2c74796456
commit 9edafeb742
2 changed files with 75 additions and 4 deletions

View File

@ -407,7 +407,7 @@ HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
LPCSTR proto, LPSTR sbuf, INT buflen)
{
struct async_query_getservbyport *aq;
unsigned int len = strlen(proto) + 1;
unsigned int len = proto ? strlen(proto) + 1 : 0;
TRACE("hwnd %p, msg %04x, port %i, proto %s\n", hWnd, uMsg, port, debugstr_a(proto));
@ -416,9 +416,17 @@ HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
SetLastError( WSAEWOULDBLOCK );
return 0;
}
aq->serv_proto = (char *)(aq + 1);
aq->serv_port = port;
strcpy( aq->serv_proto, proto );
if (proto)
{
aq->serv_proto = (char *)(aq + 1);
strcpy( aq->serv_proto, proto );
}
else
aq->serv_proto = NULL;
aq->serv_port = port;
return run_query( hWnd, uMsg, async_getservbyport, &aq->query, sbuf, buflen );
}

View File

@ -4810,6 +4810,67 @@ static void test_synchronous_WSAIoctl(void)
CloseHandle( previous_port );
}
#define WM_ASYNCCOMPLETE (WM_USER + 100)
static HWND create_async_message_window(void)
{
static const char class_name[] = "ws2_32 async message window class";
WNDCLASSEXA wndclass;
HWND hWnd;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = DefWindowProcA;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = GetModuleHandleA(NULL);
wndclass.hIcon = LoadIconA(NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIconA(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursorA(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszClassName = class_name;
wndclass.lpszMenuName = NULL;
RegisterClassExA(&wndclass);
hWnd = CreateWindow(class_name, "ws2_32 async message window", WS_OVERLAPPEDWINDOW,
0, 0, 500, 500, NULL, NULL, GetModuleHandleA(NULL), NULL);
if (!hWnd)
{
ok(0, "failed to create window: %u\n", GetLastError());
return NULL;
}
return hWnd;
}
static void test_WSAAsyncGetServByPort(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 = WSAAsyncGetServByPort(NULL, 0, 0, NULL, NULL, 0);
ok(ret != NULL, "WSAAsyncGetServByPort returned NULL\n");
ret = WSAAsyncGetServByPort(hwnd, WM_ASYNCCOMPLETE, 0, NULL, NULL, 0);
ok(ret != NULL, "WSAAsyncGetServByPort returned NULL\n");
ret = WSAAsyncGetServByPort(hwnd, WM_ASYNCCOMPLETE, htons(80), NULL, NULL, 0);
ok(ret != NULL, "WSAAsyncGetServByPort returned NULL\n");
ret = WSAAsyncGetServByPort(hwnd, WM_ASYNCCOMPLETE, htons(80), NULL, buffer, MAXGETHOSTSTRUCT);
ok(ret != NULL, "WSAAsyncGetServByPort returned NULL\n");
DestroyWindow(hwnd);
}
/**************** Main program ***************/
START_TEST( sock )
@ -4870,6 +4931,8 @@ START_TEST( sock )
test_sioRoutingInterfaceQuery();
test_WSAAsyncGetServByPort();
/* this is a io heavy test, do it at the end so the kernel doesn't start dropping packets */
test_send();
test_synchronous_WSAIoctl();