msi: Avoid using awstring in MsiGetPropertyA/W().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2018-05-15 23:03:36 -05:00 committed by Alexandre Julliard
parent 84d972010f
commit 389ad808d2
2 changed files with 62 additions and 75 deletions

View File

@ -2345,76 +2345,13 @@ int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
return val; return val;
} }
static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
awstring *szValueBuf, LPDWORD pchValueBuf )
{
MSIPACKAGE *package;
MSIRECORD *row = NULL;
UINT r = ERROR_FUNCTION_FAILED;
LPCWSTR val = NULL;
DWORD len = 0;
TRACE("%u %s %p %p\n", handle, debugstr_w(name),
szValueBuf->str.w, pchValueBuf );
if (!name)
return ERROR_INVALID_PARAMETER;
package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
if (!package)
{
LPWSTR value = NULL, buffer;
MSIHANDLE remote;
if (!(remote = msi_get_remote(handle)))
return ERROR_INVALID_HANDLE;
r = remote_GetProperty(remote, name, &value, &len);
if (r != ERROR_SUCCESS)
return r;
/* String might contain embedded nulls.
* Native returns the correct size but truncates the string. */
buffer = heap_alloc_zero((len + 1) * sizeof(WCHAR));
if (!buffer)
{
midl_user_free(value);
return ERROR_OUTOFMEMORY;
}
strcpyW(buffer, value);
r = msi_strcpy_to_awstring(buffer, len, szValueBuf, pchValueBuf);
/* Bug required by Adobe installers */
if (pchValueBuf && !szValueBuf->unicode && !szValueBuf->str.a)
*pchValueBuf *= sizeof(WCHAR);
heap_free(buffer);
midl_user_free(value);
return r;
}
row = msi_get_property_row( package->db, name );
if (row)
val = msi_record_get_string( row, 1, (int *)&len );
if (!val)
val = szEmpty;
r = msi_strcpy_to_awstring( val, len, szValueBuf, pchValueBuf );
if (row)
msiobj_release( &row->hdr );
msiobj_release( &package->hdr );
return r;
}
UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD *sz) UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD *sz)
{ {
const WCHAR *value = szEmpty;
MSIPACKAGE *package; MSIPACKAGE *package;
awstring val; MSIRECORD *row;
WCHAR *nameW; WCHAR *nameW;
int len = 0;
UINT r; UINT r;
if (!name) if (!name)
@ -2455,25 +2392,69 @@ UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD
return r; return r;
} }
val.unicode = FALSE; row = msi_get_property_row(package->db, nameW);
val.str.a = buf; if (row)
value = msi_record_get_string(row, 1, &len);
r = MSI_GetProperty(hinst, nameW, &val, sz); r = msi_strncpyWtoA(value, len, buf, sz, FALSE);
heap_free(nameW); heap_free(nameW);
if (row) msiobj_release(&row->hdr);
msiobj_release(&package->hdr); msiobj_release(&package->hdr);
return r; return r;
} }
UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, UINT WINAPI MsiGetPropertyW(MSIHANDLE hinst, const WCHAR *name, WCHAR *buf, DWORD *sz)
LPWSTR szValueBuf, LPDWORD pchValueBuf )
{ {
awstring val; const WCHAR *value = szEmpty;
MSIPACKAGE *package;
MSIRECORD *row;
int len = 0;
UINT r;
val.unicode = TRUE; if (!name)
val.str.w = szValueBuf; return ERROR_INVALID_PARAMETER;
return MSI_GetProperty( hInstall, szName, &val, pchValueBuf ); package = msihandle2msiinfo(hinst, MSIHANDLETYPE_PACKAGE);
if (!package)
{
WCHAR *value = NULL, *tmp;
MSIHANDLE remote;
DWORD len;
if (!(remote = msi_get_remote(hinst)))
return ERROR_INVALID_HANDLE;
r = remote_GetProperty(remote, name, &value, &len);
if (!r)
{
/* String might contain embedded nulls.
* Native returns the correct size but truncates the string. */
tmp = heap_alloc_zero((len + 1) * sizeof(WCHAR));
if (!tmp)
{
midl_user_free(value);
return ERROR_OUTOFMEMORY;
}
strcpyW(tmp, value);
r = msi_strncpyW(tmp, len, buf, sz);
heap_free(tmp);
}
midl_user_free(value);
return r;
}
row = msi_get_property_row(package->db, name);
if (row)
value = msi_record_get_string(row, 1, &len);
r = msi_strncpyW(value, len, buf, sz);
if (row) msiobj_release(&row->hdr);
msiobj_release(&package->hdr);
return r;
} }
MSIHANDLE __cdecl s_remote_GetActiveDatabase(MSIHANDLE hinst) MSIHANDLE __cdecl s_remote_GetActiveDatabase(MSIHANDLE hinst)

View File

@ -191,6 +191,12 @@ static void test_props(MSIHANDLE hinst)
ok(hinst, !strcmp(buffer, "xyz"), "got \"%s\"\n", buffer); ok(hinst, !strcmp(buffer, "xyz"), "got \"%s\"\n", buffer);
ok(hinst, sz == 3, "got size %u\n", sz); ok(hinst, sz == 3, "got size %u\n", sz);
r = MsiGetPropertyW(hinst, booW, NULL, NULL);
ok(hinst, !r, "got %u\n", r);
r = MsiGetPropertyW(hinst, booW, bufferW, NULL );
ok(hinst, r == ERROR_INVALID_PARAMETER, "got %u\n", r);
sz = 0; sz = 0;
r = MsiGetPropertyW(hinst, booW, NULL, &sz); r = MsiGetPropertyW(hinst, booW, NULL, &sz);
ok(hinst, !r, "got %u\n", r); ok(hinst, !r, "got %u\n", r);