Skip to content

Commit 796c6b0

Browse files
winesynclearn-more
authored andcommitted
[WINESYNC] msi: Use integers internally for MSIDBOPEN constants.
This fixes a bug where some verions of mingw and probably gcc assume that the result of pointer subtraction will be non-NULL, causing MSI_OpenDatabaseW to break when given the mode MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE. Signed-off-by: Vincent Povirk <[email protected]> Signed-off-by: Hans Leidekker <[email protected]> Signed-off-by: Alexandre Julliard <[email protected]> wine commit id cce9a5f124ae6d3fffcc7772cab6523f09a1e3d1 by Vincent Povirk <[email protected]>
1 parent 694121b commit 796c6b0

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

dll/win32/msi/database.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
144144
HRESULT r;
145145
MSIDATABASE *db = NULL;
146146
UINT ret = ERROR_FUNCTION_FAILED;
147-
LPCWSTR szMode, save_path;
147+
LPCWSTR save_path;
148+
UINT mode;
148149
STATSTG stat;
149150
BOOL created = FALSE, patch = FALSE;
150151
WCHAR path[MAX_PATH];
@@ -154,31 +155,34 @@ UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
154155
if( !pdb )
155156
return ERROR_INVALID_PARAMETER;
156157

157-
if (szPersist - MSIDBOPEN_PATCHFILE <= MSIDBOPEN_CREATEDIRECT)
158+
save_path = szDBPath;
159+
if ( IS_INTMSIDBOPEN(szPersist) )
158160
{
159-
TRACE("Database is a patch\n");
160-
szPersist -= MSIDBOPEN_PATCHFILE;
161-
patch = TRUE;
161+
mode = LOWORD(szPersist);
162162
}
163-
164-
save_path = szDBPath;
165-
szMode = szPersist;
166-
if( !IS_INTMSIDBOPEN(szPersist) )
163+
else
167164
{
168165
if (!CopyFileW( szDBPath, szPersist, FALSE ))
169166
return ERROR_OPEN_FAILED;
170167

171168
szDBPath = szPersist;
172-
szPersist = MSIDBOPEN_TRANSACT;
169+
mode = MSI_OPEN_TRANSACT;
173170
created = TRUE;
174171
}
175172

176-
if( szPersist == MSIDBOPEN_READONLY )
173+
if ((mode & MSI_OPEN_PATCHFILE) == MSI_OPEN_PATCHFILE)
174+
{
175+
TRACE("Database is a patch\n");
176+
mode &= ~MSI_OPEN_PATCHFILE;
177+
patch = TRUE;
178+
}
179+
180+
if( mode == MSI_OPEN_READONLY )
177181
{
178182
r = StgOpenStorage( szDBPath, NULL,
179183
STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
180184
}
181-
else if( szPersist == MSIDBOPEN_CREATE )
185+
else if( mode == MSI_OPEN_CREATE )
182186
{
183187
r = StgCreateDocfile( szDBPath,
184188
STGM_CREATE|STGM_TRANSACTED|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg );
@@ -187,7 +191,7 @@ UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
187191
r = db_initialize( stg, patch ? &CLSID_MsiPatch : &CLSID_MsiDatabase );
188192
created = TRUE;
189193
}
190-
else if( szPersist == MSIDBOPEN_CREATEDIRECT )
194+
else if( mode == MSI_OPEN_CREATEDIRECT )
191195
{
192196
r = StgCreateDocfile( szDBPath,
193197
STGM_CREATE|STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg );
@@ -196,19 +200,19 @@ UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
196200
r = db_initialize( stg, patch ? &CLSID_MsiPatch : &CLSID_MsiDatabase );
197201
created = TRUE;
198202
}
199-
else if( szPersist == MSIDBOPEN_TRANSACT )
203+
else if( mode == MSI_OPEN_TRANSACT )
200204
{
201205
r = StgOpenStorage( szDBPath, NULL,
202206
STGM_TRANSACTED|STGM_READWRITE|STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
203207
}
204-
else if( szPersist == MSIDBOPEN_DIRECT )
208+
else if( mode == MSI_OPEN_DIRECT )
205209
{
206210
r = StgOpenStorage( szDBPath, NULL,
207211
STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
208212
}
209213
else
210214
{
211-
ERR("unknown flag %p\n",szPersist);
215+
ERR("unknown flag %x\n",mode);
212216
return ERROR_INVALID_PARAMETER;
213217
}
214218

@@ -267,7 +271,7 @@ UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
267271
enum_stream_names( stg );
268272

269273
db->storage = stg;
270-
db->mode = szMode;
274+
db->mode = mode;
271275
if (created)
272276
db->deletefile = strdupW( szDBPath );
273277
list_init( &db->tables );
@@ -1977,7 +1981,7 @@ MSIDBSTATE WINAPI MsiGetDatabaseState( MSIHANDLE handle )
19771981
if (!(db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE )))
19781982
return MSIDBSTATE_ERROR;
19791983

1980-
if (db->mode != MSIDBOPEN_READONLY )
1984+
if (db->mode != MSI_OPEN_READONLY )
19811985
ret = MSIDBSTATE_WRITE;
19821986
msiobj_release( &db->hdr );
19831987

dll/win32/msi/msipriv.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ typedef struct tagMSITRANSFORM
9595
IStorage *stg;
9696
} MSITRANSFORM;
9797

98+
/* integer versions of the MSIDBOPEN_* constants */
99+
#define MSI_OPEN_READONLY 0
100+
#define MSI_OPEN_TRANSACT 1
101+
#define MSI_OPEN_DIRECT 2
102+
#define MSI_OPEN_CREATE 3
103+
#define MSI_OPEN_CREATEDIRECT 4
104+
#define MSI_OPEN_PATCHFILE 32
105+
98106
typedef struct tagMSIDATABASE
99107
{
100108
MSIOBJECTHDR hdr;
@@ -104,7 +112,7 @@ typedef struct tagMSIDATABASE
104112
LPWSTR path;
105113
LPWSTR deletefile;
106114
LPWSTR tempfolder;
107-
LPCWSTR mode;
115+
UINT mode;
108116
UINT media_transform_offset;
109117
UINT media_transform_disk_id;
110118
struct list tables;

dll/win32/msi/msiquery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ UINT WINAPI MsiDatabaseCommit( MSIHANDLE hdb )
981981
return ERROR_SUCCESS;
982982
}
983983

984-
if (db->mode == MSIDBOPEN_READONLY)
984+
if (db->mode == MSI_OPEN_READONLY)
985985
{
986986
msiobj_release( &db->hdr );
987987
return ERROR_SUCCESS;

0 commit comments

Comments
 (0)