combase: Fix cornercase error handling in WindowsCreateStringReference.

When WindowsCreateStringReference is given a non-null input string,
the input string must be null terminated at the given length,
even if the input length is zero.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Martin Storsjo 2015-10-29 10:21:22 +02:00 committed by Alexandre Julliard
parent 421b3ca3eb
commit bcac15a56f
2 changed files with 17 additions and 2 deletions

View File

@ -105,6 +105,8 @@ HRESULT WINAPI WindowsCreateStringReference(LPCWSTR ptr, UINT32 len,
if (out == NULL || header == NULL)
return E_INVALIDARG;
if (ptr != NULL && ptr[len] != '\0')
return E_INVALIDARG;
if (len == 0)
{
*out = NULL;
@ -112,8 +114,6 @@ HRESULT WINAPI WindowsCreateStringReference(LPCWSTR ptr, UINT32 len,
}
if (ptr == NULL)
return E_POINTER;
if (ptr[len] != '\0')
return E_INVALIDARG;
priv->buffer = (LPWSTR)ptr;
priv->length = len;
priv->reference = TRUE;

View File

@ -124,6 +124,9 @@ static void test_create_delete(void)
* length. According to MSDN this should be E_INVALIDARG, but it returns
* 0x80000017 in practice. */
ok(FAILED(pWindowsCreateStringReference(input_string, 5, &header, &str)), "Incorrect error handling\n");
/* If the input string is non-null, it must be null-terminated even if the
* length is zero. */
ok(FAILED(pWindowsCreateStringReference(input_string, 0, &header, &str)), "Incorrect error handling\n");
ok(pWindowsCreateStringReference(input_string, 6, NULL, &str) == E_INVALIDARG, "Incorrect error handling\n");
ok(pWindowsCreateStringReference(input_string, 6, &header, NULL) == E_INVALIDARG, "Incorrect error handling\n");
ok(pWindowsCreateStringReference(NULL, 6, &header, &str) == E_POINTER, "Incorrect error handling\n");
@ -138,9 +141,21 @@ static void test_create_delete(void)
ok(str == NULL, "Empty string not a null string\n");
ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
ok(pWindowsCreateString(input_string, 0, &str) == S_OK, "Failed to create string\n");
ok(str == NULL, "Empty string not a null string\n");
ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
ok(pWindowsCreateStringReference(input_empty_string, 0, &header, &str) == S_OK, "Failed to create string\n");
ok(str == NULL, "Empty string not a null string\n");
ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
ok(pWindowsCreateString(NULL, 0, &str) == S_OK, "Failed to create string\n");
ok(str == NULL, "Empty string not a null string\n");
ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
ok(pWindowsCreateStringReference(NULL, 0, &header, &str) == S_OK, "Failed to create string\n");
ok(str == NULL, "Empty string not a null string\n");
ok(pWindowsDeleteString(str) == S_OK, "Failed to delete string\n");
}
static void test_duplicate(void)