diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index e5060cbcdc6..d303bd2ecac 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -36,6 +36,8 @@ #include "wine/unicode.h" #include "objbase.h" +#include "initguid.h" + WINE_DEFAULT_DEBUG_CHANNEL(msi); /* @@ -46,6 +48,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(msi); */ #define LPCTSTR LPCWSTR +DEFINE_GUID( CLSID_MsiDatabase, 0x000c1084, 0x0000, 0x0000, 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46); + static const WCHAR szInstaller[] = { 'S','o','f','t','w','a','r','e','\\', 'M','i','c','r','o','s','o','f','t','\\', @@ -188,6 +192,7 @@ UINT WINAPI MsiOpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIHANDLE *phD MSIDATABASE *db; UINT ret; LPWSTR szMode; + STATSTG stat; TRACE("%s %s %p\n",debugstr_w(szDBPath),debugstr_w(szPersist), phDB); @@ -212,7 +217,10 @@ UINT WINAPI MsiOpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIHANDLE *phD r = StgCreateDocfile( szDBPath, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg); if( r == ERROR_SUCCESS ) + { + IStorage_SetClass( stg, &CLSID_MsiDatabase ); r = init_string_table( stg ); + } } else if( szPersist == MSIDBOPEN_TRANSACT ) { @@ -231,6 +239,23 @@ UINT WINAPI MsiOpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIHANDLE *phD return ERROR_FUNCTION_FAILED; } + r = IStorage_Stat( stg, &stat, STATFLAG_NONAME ); + if( FAILED( r ) ) + { + FIXME("Failed to stat storage\n"); + ret = ERROR_FUNCTION_FAILED; + goto end; + } + + if( memcmp( &stat.clsid, &CLSID_MsiDatabase, sizeof (GUID) ) ) + { + ERR("storage GUID is not a MSI database GUID %s\n", + debugstr_guid(&stat.clsid) ); + ret = ERROR_FUNCTION_FAILED; + goto end; + } + + handle = alloc_msihandle( MSIHANDLETYPE_DATABASE, sizeof (MSIDATABASE), MSI_CloseDatabase, (void**) &db ); if( !handle ) diff --git a/dlls/msi/record.c b/dlls/msi/record.c index 89d8bf05cd3..ae50cdd58d6 100644 --- a/dlls/msi/record.c +++ b/dlls/msi/record.c @@ -284,6 +284,9 @@ const WCHAR *MSI_RecordGetString( MSIHANDLE handle, unsigned int iField ) if( iField > rec->count ) return NULL; + if( rec->fields[iField].type != MSIFIELD_WSTR ) + return NULL; + return rec->fields[iField].u.szwVal; } diff --git a/dlls/msi/string.c b/dlls/msi/string.c index bda5895df07..fa69ebc57a1 100644 --- a/dlls/msi/string.c +++ b/dlls/msi/string.c @@ -143,6 +143,8 @@ int msi_addstring( string_table *st, int n, const CHAR *data, int len, UINT refc { int sz; + if( !data ) + return 0; if( !data[0] ) return 0; if( n > 0 ) @@ -189,6 +191,8 @@ int msi_addstringW( string_table *st, int n, const WCHAR *data, int len, UINT re { /* TRACE("[%2d] = %s\n", string_no, debugstr_an(data,len) ); */ + if( !data ) + return 0; if( !data[0] ) return 0; if( n > 0 )