dpnet: Add check for mismatched string lengths.
This commit is contained in:
parent
b12f73a591
commit
a5d3125395
|
@ -382,11 +382,43 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address *
|
||||||
struct component *entry;
|
struct component *entry;
|
||||||
BOOL found = FALSE;
|
BOOL found = FALSE;
|
||||||
|
|
||||||
TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
|
TRACE("(%p, %s, %p, %u, %x)\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
|
||||||
|
|
||||||
if (NULL == lpvData)
|
if (NULL == lpvData)
|
||||||
return DPNERR_INVALIDPOINTER;
|
return DPNERR_INVALIDPOINTER;
|
||||||
|
|
||||||
|
switch (dwDataType)
|
||||||
|
{
|
||||||
|
case DPNA_DATATYPE_DWORD:
|
||||||
|
if (sizeof(DWORD) != dwDataSize)
|
||||||
|
{
|
||||||
|
WARN("Invalid DWORD size, returning DPNERR_INVALIDPARAM\n");
|
||||||
|
return DPNERR_INVALIDPARAM;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_GUID:
|
||||||
|
if (sizeof(GUID) != dwDataSize)
|
||||||
|
{
|
||||||
|
WARN("Invalid GUID size, returning DPNERR_INVALIDPARAM\n");
|
||||||
|
return DPNERR_INVALIDPARAM;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_STRING:
|
||||||
|
if (((strlenW((WCHAR*)lpvData)+1)*sizeof(WCHAR)) != dwDataSize)
|
||||||
|
{
|
||||||
|
WARN("Invalid STRING size, returning DPNERR_INVALIDPARAM\n");
|
||||||
|
return DPNERR_INVALIDPARAM;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DPNA_DATATYPE_STRING_ANSI:
|
||||||
|
if ((strlen((const CHAR*)lpvData)+1) != dwDataSize)
|
||||||
|
{
|
||||||
|
WARN("Invalid ASCII size, returning DPNERR_INVALIDPARAM\n");
|
||||||
|
return DPNERR_INVALIDPARAM;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
LIST_FOR_EACH_ENTRY(entry, &This->components, struct component, entry)
|
LIST_FOR_EACH_ENTRY(entry, &This->components, struct component, entry)
|
||||||
{
|
{
|
||||||
if (lstrcmpW(pwszName, entry->name) == 0)
|
if (lstrcmpW(pwszName, entry->name) == 0)
|
||||||
|
@ -411,16 +443,10 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address *
|
||||||
switch (dwDataType)
|
switch (dwDataType)
|
||||||
{
|
{
|
||||||
case DPNA_DATATYPE_DWORD:
|
case DPNA_DATATYPE_DWORD:
|
||||||
if (sizeof(DWORD) != dwDataSize)
|
|
||||||
return DPNERR_INVALIDPARAM;
|
|
||||||
|
|
||||||
entry->data.value = *(DWORD*)lpvData;
|
entry->data.value = *(DWORD*)lpvData;
|
||||||
TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
|
TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
|
||||||
break;
|
break;
|
||||||
case DPNA_DATATYPE_GUID:
|
case DPNA_DATATYPE_GUID:
|
||||||
if (sizeof(GUID) != dwDataSize)
|
|
||||||
return DPNERR_INVALIDPARAM;
|
|
||||||
|
|
||||||
entry->data.guid = *(GUID*)lpvData;
|
entry->data.guid = *(GUID*)lpvData;
|
||||||
TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
|
TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -71,6 +71,7 @@ static void address_addcomponents(void)
|
||||||
{
|
{
|
||||||
static const WCHAR UNKNOWN[] = { 'u','n','k','n','o','w','n',0 };
|
static const WCHAR UNKNOWN[] = { 'u','n','k','n','o','w','n',0 };
|
||||||
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
|
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
|
||||||
|
static const char testing[] = "testing";
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
IDirectPlay8Address *localaddr = NULL;
|
IDirectPlay8Address *localaddr = NULL;
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ static void address_addcomponents(void)
|
||||||
DWORD namelen = 0;
|
DWORD namelen = 0;
|
||||||
DWORD bufflen = 0;
|
DWORD bufflen = 0;
|
||||||
DWORD port = 8888;
|
DWORD port = 8888;
|
||||||
|
WCHAR buffer[256];
|
||||||
|
|
||||||
/* We can add any Component to the Address interface not just the predefined ones. */
|
/* We can add any Component to the Address interface not just the predefined ones. */
|
||||||
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID), DPNA_DATATYPE_GUID);
|
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID), DPNA_DATATYPE_GUID);
|
||||||
|
@ -93,9 +95,39 @@ static void address_addcomponents(void)
|
||||||
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID)+1, DPNA_DATATYPE_GUID);
|
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID)+1, DPNA_DATATYPE_GUID);
|
||||||
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)+2, DPNA_DATATYPE_STRING);
|
||||||
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)/2, DPNA_DATATYPE_STRING);
|
||||||
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, testing, sizeof(testing)+2, DPNA_DATATYPE_STRING_ANSI);
|
||||||
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
/* Show that on error, nothing is added. */
|
||||||
|
size = sizeof(buffer);
|
||||||
|
hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, buffer, &size, &type);
|
||||||
|
ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, testing, sizeof(testing), DPNA_DATATYPE_STRING_ANSI);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
|
||||||
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
|
||||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
/* The information doesn't get removed when invalid parameters are used.*/
|
||||||
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost)+2, DPNA_DATATYPE_STRING);
|
||||||
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
size = sizeof(buffer);
|
||||||
|
hr = IDirectPlay8Address_GetComponentByName(localaddr, DPNA_KEY_HOSTNAME, buffer, &size, &type);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
todo_wine ok(type == DPNA_DATATYPE_STRING, "incorrect type %d\n", type);
|
||||||
|
todo_wine ok(!lstrcmpW(buffer, localhost), "Invalid string: %s\n", wine_dbgstr_w(buffer));
|
||||||
|
|
||||||
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
|
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
|
||||||
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue