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

Andreas Mohr).
Removed a couple of unnecessary version checks.
This commit is contained in:
Alexandre Julliard 2004-07-24 02:32:50 +00:00
parent d0e5b8e2ee
commit bba76fca45
2 changed files with 22 additions and 20 deletions

View File

@ -868,16 +868,6 @@ DWORD WINAPI RegDeleteKeyW( HKEY hkey, LPCWSTR name )
} }
else if (!(ret = RegOpenKeyExW( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp ))) 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 ) ); ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
RegCloseKey( tmp ); RegCloseKey( tmp );
} }
@ -947,21 +937,14 @@ DWORD WINAPI RegDeleteKeyA( HKEY hkey, LPCSTR name )
* RETURNS * RETURNS
* Success: ERROR_SUCCESS * Success: ERROR_SUCCESS
* Failure: Error code * 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 WINAPI RegSetValueExW( HKEY hkey, LPCWSTR name, DWORD reserved,
DWORD type, CONST BYTE *data, DWORD count ) DWORD type, CONST BYTE *data, DWORD count )
{ {
UNICODE_STRING nameW; UNICODE_STRING nameW;
if (!is_version_nt()) /* win95 */ /* no need for version check, not implemented on win9x anyway */
{ if (count && is_string(type))
if (type == REG_SZ) count = (strlenW( (WCHAR *)data ) + 1) * sizeof(WCHAR);
}
else if (count && is_string(type))
{ {
LPCWSTR str = (LPCWSTR)data; LPCWSTR str = (LPCWSTR)data;
/* if user forgot to count terminating null, add it (yes NT does this) */ /* 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.@] * RegSetValueExA [ADVAPI32.@]
* *
* see RegSetValueExW * 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, DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
CONST BYTE *data, DWORD count ) 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 (!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)) else if (count && is_string(type))
{ {

View File

@ -67,6 +67,17 @@ static void test_enum_value(void)
static const WCHAR testW[] = {'T','e','s','t',0}; static const WCHAR testW[] = {'T','e','s','t',0};
static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',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 ); res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
ok( res == 0, "RegSetValueExA failed error %ld\n", res ); ok( res == 0, "RegSetValueExA failed error %ld\n", res );