Skip to content

Commit

Permalink
Issue python#24594: Validates persist parameter when opening MSI data…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
zooba committed Sep 9, 2016
1 parent 94a7927 commit 6ceda63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Core and Builtins
Library
-------

- Issue #24594: Validates persist parameter when opening MSI database

- Issue #28047: Fixed calculation of line length used for the base64 CTE
in the new email policies.

Expand Down
20 changes: 17 additions & 3 deletions PC/_msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,18 +955,32 @@ static PyTypeObject msidb_Type = {
0, /*tp_is_gc*/
};

#define Py_NOT_PERSIST(x, flag) \
(x != (int)(flag) && \
x != ((int)(flag) | MSIDBOPEN_PATCHFILE))

#define Py_INVALID_PERSIST(x) \
(Py_NOT_PERSIST(x, MSIDBOPEN_READONLY) && \
Py_NOT_PERSIST(x, MSIDBOPEN_TRANSACT) && \
Py_NOT_PERSIST(x, MSIDBOPEN_DIRECT) && \
Py_NOT_PERSIST(x, MSIDBOPEN_CREATE) && \
Py_NOT_PERSIST(x, MSIDBOPEN_CREATEDIRECT))

static PyObject* msiopendb(PyObject *obj, PyObject *args)
{
int status;
char *path;
int persist;
MSIHANDLE h;
msiobj *result;

if (!PyArg_ParseTuple(args, "si:MSIOpenDatabase", &path, &persist))
return NULL;

status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
/* We need to validate that persist is a valid MSIDBOPEN_* value. Otherwise,
MsiOpenDatabase may treat the value as a pointer, leading to unexpected
behavior. */
if (Py_INVALID_PERSIST(persist))
return msierror(ERROR_INVALID_PARAMETER);
status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
if (status != ERROR_SUCCESS)
return msierror(status);

Expand Down

0 comments on commit 6ceda63

Please sign in to comment.