Francois Gouget : advapi32/tests: Cleanup test_hkey_main_Value_[AW]().
Alexandre Julliard
julliard at winehq.org
Fri Nov 21 06:54:44 CST 2008
Module: wine
Branch: master
Commit: 9ce2bd20e4e9faf230446b49747a7af95d2d2030
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9ce2bd20e4e9faf230446b49747a7af95d2d2030
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Thu Nov 20 20:46:34 2008 +0100
advapi32/tests: Cleanup test_hkey_main_Value_[AW]().
Fix a byte vs. WCHAR count issue in test_hkey_main_Value_W().
Check that RegQueryValueEx[AW]() did not write more data than expected.
---
dlls/advapi32/tests/registry.c | 39 ++++++++++++++++++++-------------------
1 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 95608c6..29342d0 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -204,8 +204,7 @@ static void test_hkey_main_Value_A(LPCSTR name, LPCSTR string,
{
DWORD ret, type, cbData;
DWORD str_byte_len;
- LPSTR value;
- static const char nA[]={'N', 0};
+ BYTE* value;
type=0xdeadbeef;
cbData=0xdeadbeef;
@@ -225,23 +224,24 @@ static void test_hkey_main_Value_A(LPCSTR name, LPCSTR string,
ok(cbData == full_byte_len || cbData == str_byte_len /* Win9x */,
"cbData=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
- value = HeapAlloc(GetProcessHeap(), 0, (cbData+2)*sizeof(*value));
- strcpy(value, nA);
+ value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
+ memset(value, 0xbd, cbData+1);
type=0xdeadbeef;
- ret = RegQueryValueExA(hkey_main, name, NULL, &type, (BYTE*)value, &cbData);
+ ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
GLE = GetLastError();
ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%d\n", ret, GLE);
if (!string)
{
/* When cbData == 0, RegQueryValueExA() should not modify the buffer */
- ok(strcmp(value, nA) == 0 || (cbData == 1 && *value == '\0') /* Win9x */,
- "RegQueryValueExA failed: '%s' != '%s'\n", value, string);
+ ok(*value == 0xbd || (cbData == 1 && *value == '\0') /* Win9x */,
+ "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
}
else
{
ok(memcmp(value, string, cbData) == 0, "RegQueryValueExA failed: %s/%d != %s/%d\n",
- wine_debugstr_an(value, cbData), cbData,
+ wine_debugstr_an((char*)value, cbData), cbData,
wine_debugstr_an(string, full_byte_len), full_byte_len);
+ ok(*(value+cbData) == 0xbd, "RegQueryValueExA overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
}
HeapFree(GetProcessHeap(), 0, value);
}
@@ -250,8 +250,7 @@ static void test_hkey_main_Value_W(LPCWSTR name, LPCWSTR string,
DWORD full_byte_len)
{
DWORD ret, type, cbData;
- LPWSTR value;
- static const WCHAR nW[]={'N', 0};
+ BYTE* value;
type=0xdeadbeef;
cbData=0xdeadbeef;
@@ -272,20 +271,22 @@ static void test_hkey_main_Value_W(LPCWSTR name, LPCWSTR string,
ok(cbData == full_byte_len,
"cbData=%d instead of %d\n", cbData, full_byte_len);
- value = HeapAlloc(GetProcessHeap(), 0, (cbData+2)*sizeof(*value));
- lstrcpyW(value, nW);
+ /* Give enough space to overflow by one WCHAR */
+ value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
+ memset(value, 0xbd, cbData+2);
type=0xdeadbeef;
- ret = RegQueryValueExW(hkey_main, name, NULL, &type, (BYTE*)value, &cbData);
+ ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
GLE = GetLastError();
ok(ret == ERROR_SUCCESS, "RegQueryValueExW failed: %d, GLE=%d\n", ret, GLE);
- if (!string)
+ if (string)
{
- /* When cbData == 0, RegQueryValueExW() should not modify the buffer */
- string=nW;
+ ok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
+ wine_debugstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
+ wine_debugstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
}
- ok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
- wine_debugstr_wn(value, cbData / sizeof(WCHAR)), cbData,
- wine_debugstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
+ /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
+ ok(*(value+cbData) == 0xbd, "RegQueryValueExW overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
+ ok(*(value+cbData+1) == 0xbd, "RegQueryValueExW overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
HeapFree(GetProcessHeap(), 0, value);
}
More information about the wine-cvs
mailing list