From: Zebediah Figura zfigura@codeweavers.com
--- dlls/setupapi/install.c | 29 ++++++++++++++++++++++------- dlls/setupapi/tests/install.c | 4 ++-- 2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/dlls/setupapi/install.c b/dlls/setupapi/install.c index 532ac6c36a6..435918e815e 100644 --- a/dlls/setupapi/install.c +++ b/dlls/setupapi/install.c @@ -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; } diff --git a/dlls/setupapi/tests/install.c b/dlls/setupapi/tests/install.c index 0334450dfce..10c93482ece 100644 --- a/dlls/setupapi/tests/install.c +++ b/dlls/setupapi/tests/install.c @@ -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);