[PATCH 8/8] advapi32: Fail in RegEnumValue on missing value or val_count parameters.
Bernhard Übelacker
bernhardu at vr-web.de
Tue Jun 30 07:38:06 CDT 2015
Bug #38796
Because tests would crash on accessing the val_count parameter here are
tests and fix in a single patch.
---
dlls/advapi32/registry.c | 8 +++----
dlls/advapi32/tests/registry.c | 52 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 30130b1..cf5a1ac 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -1912,8 +1912,8 @@ LSTATUS WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_
TRACE("(%p,%d,%p,%p,%p,%p,%p,%p)\n",
hkey, index, value, val_count, reserved, type, data, count );
- /* NT only checks count, not val_count */
- if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
+ if ((data && !count) || reserved || !value || !val_count)
+ return ERROR_INVALID_PARAMETER;
if (!(hkey = get_special_root_hkey( hkey, 0 ))) return ERROR_INVALID_HANDLE;
total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
@@ -1997,8 +1997,8 @@ LSTATUS WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_c
TRACE("(%p,%d,%p,%p,%p,%p,%p,%p)\n",
hkey, index, value, val_count, reserved, type, data, count );
- /* NT only checks count, not val_count */
- if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
+ if ((data && !count) || reserved || !value || !val_count)
+ return ERROR_INVALID_PARAMETER;
if (!(hkey = get_special_root_hkey( hkey, 0 ))) return ERROR_INVALID_HANDLE;
total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index c801384..b8b7e1c 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -643,6 +643,32 @@ static void test_enum_value(void)
ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
+ if (pRegGetValueA) /* avoid a crash on Windows 2000 */
+ {
+ /* no value and no val_count parameter */
+ data_count = 20;
+ type = 1234;
+ strcpy( data, "xxxxxxxxxx" );
+ res = RegEnumValueA( test_key, 0, NULL, NULL, NULL, &type, (BYTE*)data, &data_count );
+ ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
+
+ /* no value parameter */
+ val_count = 20;
+ data_count = 20;
+ type = 1234;
+ strcpy( data, "xxxxxxxxxx" );
+ res = RegEnumValueA( test_key, 0, NULL, &val_count, NULL, &type, (BYTE*)data, &data_count );
+ ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
+
+ /* no val_count parameter */
+ data_count = 20;
+ type = 1234;
+ strcpy( value, "xxxxxxxxxx" );
+ strcpy( data, "xxxxxxxxxx" );
+ res = RegEnumValueA( test_key, 0, value, NULL, NULL, &type, (BYTE*)data, &data_count );
+ ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
+ }
+
/* Unicode tests */
SetLastError(0xdeadbeef);
@@ -710,6 +736,32 @@ static void test_enum_value(void)
ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
+ if (pRegGetValueA) /* avoid a crash on Windows 2000 */
+ {
+ /* no valueW and no val_count parameter */
+ data_count = 20;
+ type = 1234;
+ memcpy( dataW, xxxW, sizeof(xxxW) );
+ res = RegEnumValueW( test_key, 0, NULL, NULL, NULL, &type, (BYTE*)dataW, &data_count );
+ ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
+
+ /* no valueW parameter */
+ val_count = 20;
+ data_count = 20;
+ type = 1234;
+ memcpy( dataW, xxxW, sizeof(xxxW) );
+ res = RegEnumValueW( test_key, 0, NULL, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
+ ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
+
+ /* no val_count parameter */
+ data_count = 20;
+ type = 1234;
+ memcpy( valueW, xxxW, sizeof(xxxW) );
+ memcpy( dataW, xxxW, sizeof(xxxW) );
+ res = RegEnumValueW( test_key, 0, valueW, NULL, NULL, &type, (BYTE*)dataW, &data_count );
+ ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
+ }
+
cleanup:
RegDeleteKeyA(test_key, "");
RegCloseKey(test_key);
--
2.1.4
More information about the wine-patches
mailing list