Andrew Nguyen : ws2_32: Avoid a crash with an optional pointer in WSAAsyncGetServByPort.
Alexandre Julliard
julliard at winehq.org
Wed Jun 1 12:11:09 CDT 2011
Module: wine
Branch: master
Commit: 9edafeb742d8ce0436e7e055998a94957cfacdd9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9edafeb742d8ce0436e7e055998a94957cfacdd9
Author: Andrew Nguyen <anguyen at codeweavers.com>
Date: Wed Jun 1 07:14:18 2011 -0500
ws2_32: Avoid a crash with an optional pointer in WSAAsyncGetServByPort.
---
dlls/ws2_32/async.c | 16 ++++++++---
dlls/ws2_32/tests/sock.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 4 deletions(-)
diff --git a/dlls/ws2_32/async.c b/dlls/ws2_32/async.c
index ce28142..01d5d48 100644
--- a/dlls/ws2_32/async.c
+++ b/dlls/ws2_32/async.c
@@ -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 );
}
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 5db9013..f6a3e57 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -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();
More information about the wine-cvs
mailing list