Commit bba76fca authored by Alexandre Julliard's avatar Alexandre Julliard

Don't crash on NULL data in RegSetValueExA (reported by Mike Hearn and

Andreas Mohr). Removed a couple of unnecessary version checks.
parent d0e5b8e2
......@@ -868,16 +868,6 @@ DWORD WINAPI RegDeleteKeyW( HKEY hkey, LPCWSTR name )
}
else if (!(ret = RegOpenKeyExW( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
{
if (!is_version_nt()) /* win95 does recursive key deletes */
{
WCHAR name[MAX_PATH];
while(!RegEnumKeyW(tmp, 0, name, sizeof(name)))
{
if(RegDeleteKeyW(tmp, name)) /* recurse */
break;
}
}
ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
RegCloseKey( tmp );
}
......@@ -947,21 +937,14 @@ DWORD WINAPI RegDeleteKeyA( HKEY hkey, LPCSTR name )
* RETURNS
* Success: ERROR_SUCCESS
* Failure: Error code
*
* NOTES
* win95 does not care about count for REG_SZ and finds out the len by itself (js)
* NT does definitely care (aj)
*/
DWORD WINAPI RegSetValueExW( HKEY hkey, LPCWSTR name, DWORD reserved,
DWORD type, CONST BYTE *data, DWORD count )
{
UNICODE_STRING nameW;
if (!is_version_nt()) /* win95 */
{
if (type == REG_SZ) count = (strlenW( (WCHAR *)data ) + 1) * sizeof(WCHAR);
}
else if (count && is_string(type))
/* no need for version check, not implemented on win9x anyway */
if (count && is_string(type))
{
LPCWSTR str = (LPCWSTR)data;
/* if user forgot to count terminating null, add it (yes NT does this) */
......@@ -979,6 +962,10 @@ DWORD WINAPI RegSetValueExW( HKEY hkey, LPCWSTR name, DWORD reserved,
* RegSetValueExA [ADVAPI32.@]
*
* see RegSetValueExW
*
* NOTES
* win95 does not care about count for REG_SZ and finds out the len by itself (js)
* NT does definitely care (aj)
*/
DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
CONST BYTE *data, DWORD count )
......@@ -989,7 +976,11 @@ DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
if (!is_version_nt()) /* win95 */
{
if (type == REG_SZ) count = strlen(data) + 1;
if (type == REG_SZ)
{
if (!data) return ERROR_INVALID_PARAMETER;
count = strlen(data) + 1;
}
}
else if (count && is_string(type))
{
......
......@@ -67,6 +67,17 @@ static void test_enum_value(void)
static const WCHAR testW[] = {'T','e','s','t',0};
static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
/* check NULL data with zero length */
res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, NULL, 0 );
if (GetVersion() & 0x80000000)
ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res );
else
ok( !res, "RegSetValueExA returned %ld\n", res );
res = RegSetValueExA( hkey_main, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
ok( !res, "RegSetValueExA returned %ld\n", res );
res = RegSetValueExA( hkey_main, "Test", 0, REG_BINARY, NULL, 0 );
ok( !res, "RegSetValueExA returned %ld\n", res );
res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
ok( res == 0, "RegSetValueExA failed error %ld\n", res );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment