msi: Prevent uninitialized variable usage.

Observed with Lync 2010 setup in ReactOS. The embedded Silverlight
setup hits this case (no LASTUSEDSOURCE in the registry).

Signed-off-by: Mark Jansen <mark.jansen@reactos.org>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Mark Jansen 2019-02-18 10:00:57 +01:00 committed by Alexandre Julliard
parent c91f254a77
commit 145b410920
2 changed files with 46 additions and 9 deletions

View File

@ -592,8 +592,11 @@ UINT WINAPI MsiSourceListGetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
0, 0, NULL, &size);
if (rc != ERROR_SUCCESS)
{
RegCloseKey(sourcekey);
return ERROR_SUCCESS;
static WCHAR szEmpty[1] = { '\0' };
rc = ERROR_SUCCESS;
source = NULL;
ptr = szEmpty;
goto output_out;
}
source = msi_alloc(size);
@ -627,7 +630,7 @@ UINT WINAPI MsiSourceListGetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
else
ptr++;
}
output_out:
if (szValue)
{
if (strlenW(ptr) < *pcchValue)

View File

@ -48,6 +48,8 @@ static UINT (WINAPI *pMsiSourceListEnumSourcesA)
(LPCSTR, LPCSTR, MSIINSTALLCONTEXT, DWORD, DWORD, LPSTR, LPDWORD);
static UINT (WINAPI *pMsiSourceListGetInfoA)
(LPCSTR, LPCSTR, MSIINSTALLCONTEXT, DWORD, LPCSTR, LPSTR, LPDWORD);
static UINT (WINAPI *pMsiSourceListGetInfoW)
(LPCWSTR, LPCWSTR, MSIINSTALLCONTEXT, DWORD, LPCWSTR, LPWSTR, LPDWORD);
static UINT (WINAPI *pMsiSourceListSetInfoA)
(LPCSTR, LPCSTR, MSIINSTALLCONTEXT, DWORD,LPCSTR, LPCSTR);
static UINT (WINAPI *pMsiSourceListAddSourceA)
@ -69,6 +71,7 @@ static void init_functionpointers(void)
GET_PROC(hmsi, MsiSourceListEnumMediaDisksA)
GET_PROC(hmsi, MsiSourceListEnumSourcesA)
GET_PROC(hmsi, MsiSourceListGetInfoA)
GET_PROC(hmsi, MsiSourceListGetInfoW)
GET_PROC(hmsi, MsiSourceListSetInfoA)
GET_PROC(hmsi, MsiSourceListAddSourceA)
@ -179,14 +182,21 @@ static void check_reg_str(HKEY prodkey, LPCSTR name, LPCSTR expected, BOOL bcase
#define CHECK_REG_STR(prodkey, name, expected) \
check_reg_str(prodkey, name, expected, TRUE, __LINE__);
static inline WCHAR *strdupAW( const char *str )
{
int len;
WCHAR *ret;
len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
if (!(ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
return ret;
}
static void test_MsiSourceListGetInfo(void)
{
CHAR prodcode[MAX_PATH];
CHAR prod_squashed[MAX_PATH];
CHAR keypath[MAX_PATH*2];
CHAR value[MAX_PATH];
LPSTR usersid;
LPCSTR data;
char prodcode[MAX_PATH], prod_squashed[MAX_PATH], keypath[MAX_PATH * 2], value[MAX_PATH], *usersid;
WCHAR valueW[MAX_PATH], *usersidW, *prodcodeW;
const char *data;
LONG res;
UINT r;
HKEY userkey, hkey, media;
@ -416,6 +426,30 @@ static void test_MsiSourceListGetInfo(void)
ok(!lstrcmpA(value, "prompt"), "Expected \"prompt\", got \"%s\"\n", value);
ok(size == 6, "Expected 6, got %d\n", size);
/* LastUsedSource value doesn't exist */
RegDeleteValueA(hkey, "LastUsedSource");
size = MAX_PATH;
memset(value, 0x55, sizeof(value));
r = pMsiSourceListGetInfoA(prodcode, usersid, MSIINSTALLCONTEXT_USERUNMANAGED,
MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEA,
value, &size);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
ok(!lstrcmpA(value, ""), "Expected \"\", got \"%s\"\n", value);
ok(size == 0, "Expected 0, got %d\n", size);
size = MAX_PATH;
usersidW = strdupAW(usersid);
prodcodeW = strdupAW(prodcode);
memset(valueW, 0x55, sizeof(valueW));
r = pMsiSourceListGetInfoW(prodcodeW, usersidW, MSIINSTALLCONTEXT_USERUNMANAGED,
MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW,
valueW, &size);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
ok(!valueW[0], "Expected \"\"");
ok(size == 0, "Expected 0, got %d\n", size);
HeapFree(GetProcessHeap(), 0, usersidW);
HeapFree(GetProcessHeap(), 0, prodcodeW);
data = "";
res = RegSetValueExA(hkey, "LastUsedSource", 0, REG_SZ,
(const BYTE *)data, lstrlenA(data) + 1);