From: Alistair Leslie-Hughes Subject: [1/3] dpnet: Improve Error checking in IDirectPlay8Address Get/SetSP Message-Id: <52DC928B.1020608@hotmail.com> Date: Mon, 20 Jan 2014 14:05:47 +1100 Hi, Changelog: dpnet: Improve Error checking in IDirectPlay8Address Get/SetSP Best Regards Alistair Leslie-Hughes >From 27a581e098dc765792a075eead6111c961ae7f30 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Fri, 17 Jan 2014 09:38:13 +1100 Subject: [PATCH] Improve Error checking in Get/Set SP To: wine-patches --- dlls/dpnet/address.c | 28 +++++++++++----- dlls/dpnet/tests/Makefile.in | 3 +- dlls/dpnet/tests/address.c | 80 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 dlls/dpnet/tests/address.c diff --git a/dlls/dpnet/address.c b/dlls/dpnet/address.c index 78c8350..d12ef01 100644 --- a/dlls/dpnet/address.c +++ b/dlls/dpnet/address.c @@ -36,6 +36,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(dpnet); +DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); + static inline IDirectPlay8AddressImpl *impl_from_IDirectPlay8Address(IDirectPlay8Address *iface) { return CONTAINING_RECORD(iface, IDirectPlay8AddressImpl, IDirectPlay8Address_iface); @@ -166,12 +168,18 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address *iface static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address *iface, GUID *pguidSP) { - IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); + IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); - TRACE("(%p, %p)\n", iface, pguidSP); + TRACE("(%p, %p)\n", iface, pguidSP); - *pguidSP = This->SP_guid; - return DPN_OK; + if(!pguidSP) + return DPNERR_INVALIDPOINTER; + + if(IsEqualGUID(&This->SP_guid, &GUID_NULL)) + return DPNERR_DOESNOTEXIST; + + *pguidSP = This->SP_guid; + return DPN_OK; } static HRESULT WINAPI IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address *iface, @@ -185,12 +193,15 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address *i static HRESULT WINAPI IDirectPlay8AddressImpl_SetSP(IDirectPlay8Address *iface, const GUID *const pguidSP) { - IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); + IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); - TRACE("(%p, %s)\n", iface, debugstr_SP(pguidSP)); + TRACE("(%p, %s)\n", iface, debugstr_SP(pguidSP)); - This->SP_guid = *pguidSP; - return DPN_OK; + if(!pguidSP) + return DPNERR_INVALIDPOINTER; + + This->SP_guid = *pguidSP; + return DPN_OK; } static HRESULT WINAPI IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address *iface, @@ -313,6 +324,7 @@ HRESULT DPNET_CreateDirectPlay8Address(LPCLASSFACTORY iface, LPUNKNOWN punkOuter return E_OUTOFMEMORY; } client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl; + client->SP_guid = GUID_NULL; client->ref = 0; /* will be inited with QueryInterface */ return IDirectPlay8AddressImpl_QueryInterface (&client->IDirectPlay8Address_iface, riid, ppobj); } diff --git a/dlls/dpnet/tests/Makefile.in b/dlls/dpnet/tests/Makefile.in index 9220121..673e857 100644 --- a/dlls/dpnet/tests/Makefile.in +++ b/dlls/dpnet/tests/Makefile.in @@ -1,6 +1,7 @@ TESTDLL = dpnet.dll -IMPORTS = dpnet ole32 +IMPORTS = ole32 C_SRCS = \ + address.c \ peer.c \ server.c diff --git a/dlls/dpnet/tests/address.c b/dlls/dpnet/tests/address.c new file mode 100644 index 0000000..3baf50a --- /dev/null +++ b/dlls/dpnet/tests/address.c @@ -0,0 +1,80 @@ +/* + * Copyright 2014 Alistair Leslie-Hughes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#define WIN32_LEAN_AND_MEAN +#include + +#include +#include "wine/test.h" + +static char *show_guid(const GUID *guid) +{ + static char buf[39]; + sprintf(buf, + "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + guid->Data1, guid->Data2, guid->Data3, + guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], + guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); + + return buf; +} + +static void create_directplay_address(void) +{ + HRESULT hr; + IDirectPlay8Address *localaddr = NULL; + + hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr); + ok(hr == S_OK, "Failed to create IDirectPlay8Address object"); + if( SUCCEEDED(hr) ) + { + GUID guidsp; + + hr = IDirectPlay8Address_GetSP(localaddr, NULL); + ok(hr == DPNERR_INVALIDPOINTER, "GetSP failed 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetSP(localaddr, &guidsp); + ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_SetSP(localaddr, NULL); + ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetSP(localaddr, &guidsp); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(IsEqualGUID(&guidsp, &CLSID_DP8SP_TCPIP), "wrong guid: %s\n", show_guid(&guidsp)); + + IDirectPlay8Address_Release(localaddr); + } +} + +START_TEST(address) +{ + HRESULT hr; + + hr = CoInitialize(0); + ok( hr == S_OK, "failed to init com\n"); + if (hr != S_OK) + return; + + create_directplay_address(); + + CoUninitialize(); +} -- 1.8.3.2