setupapi: Fail installation when trying to append to a registry value of the wrong type.

This commit is contained in:
Zebediah Figura 2023-02-06 19:36:49 -06:00 committed by Alexandre Julliard
parent d7c8279c08
commit 0ab56b88df
2 changed files with 24 additions and 9 deletions

View file

@ -19,6 +19,7 @@
*/
#include <stdarg.h>
#include <stdbool.h>
#define COBJMACROS
@ -227,17 +228,26 @@ static HKEY get_root_key( const WCHAR *name, HKEY def_root )
*
* Append a multisz string to a multisz registry value.
*/
static void append_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *strings,
static bool append_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *strings,
DWORD str_size )
{
DWORD size, type, total;
WCHAR *buffer, *p;
if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return;
if (type != REG_MULTI_SZ) return;
if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return true;
if (type != REG_MULTI_SZ)
{
WARN( "value %s exists but has wrong type %#lx\n", debugstr_w(value), type );
SetLastError( ERROR_INVALID_DATA );
return false;
}
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size + str_size) * sizeof(WCHAR) ))) return;
if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size )) goto done;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (size + str_size) * sizeof(WCHAR) ))) return false;
if (RegQueryValueExW( hkey, value, NULL, NULL, (BYTE *)buffer, &size ))
{
HeapFree( GetProcessHeap(), 0, buffer );
return false;
}
/* compare each string against all the existing ones */
total = size;
@ -261,8 +271,9 @@ static void append_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *s
TRACE( "setting value %s to %s\n", debugstr_w(value), debugstr_w(buffer) );
RegSetValueExW( hkey, value, 0, REG_MULTI_SZ, (BYTE *)buffer, total );
}
done:
HeapFree( GetProcessHeap(), 0, buffer );
return true;
}
@ -374,7 +385,11 @@ static BOOL do_reg_operation( HKEY hkey, const WCHAR *value, INFCONTEXT *context
if (flags & FLG_ADDREG_APPEND)
{
if (!str) return TRUE;
append_multi_sz_value( hkey, value, str, size );
if (!append_multi_sz_value( hkey, value, str, size ))
{
HeapFree( GetProcessHeap(), 0, str );
return FALSE;
}
HeapFree( GetProcessHeap(), 0, str );
return TRUE;
}

View file

@ -2376,8 +2376,8 @@ static void test_append_reg(void)
ret = SetupInstallFromInfSectionA(NULL, hinf, "DefaultInstall", SPINST_REGISTRY,
NULL, "C:\\", 0, SetupDefaultQueueCallbackA, context, NULL, NULL);
todo_wine ok(!ret, "Expected failure.\n");
todo_wine ok(GetLastError() == ERROR_INVALID_DATA, "Got error %#lx.\n", GetLastError());
ok(!ret, "Expected failure.\n");
ok(GetLastError() == ERROR_INVALID_DATA, "Got error %#lx.\n", GetLastError());
size = sizeof(value);
l = RegQueryValueExA(key, "value", NULL, &type, (BYTE *)value, &size);