diff options
author | Steve Dower <steve.dower@microsoft.com> | 2016-09-09 18:56:34 (GMT) |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2016-09-09 18:56:34 (GMT) |
commit | 6ceda631af2717c271e0b5b2b05a036463764418 (patch) | |
tree | a2e81fcfbe239baf353ac9c8b25bddef284db107 /PC/_msi.c | |
parent | 94a7927cc6ad7c2fa986cc207f1f655eb017fa18 (diff) | |
download | cpython-6ceda631af2717c271e0b5b2b05a036463764418.zip cpython-6ceda631af2717c271e0b5b2b05a036463764418.tar.gz cpython-6ceda631af2717c271e0b5b2b05a036463764418.tar.bz2 |
Issue #24594: Validates persist parameter when opening MSI database
Diffstat (limited to 'PC/_msi.c')
-rw-r--r-- | PC/_msi.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -955,6 +955,17 @@ 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; @@ -962,11 +973,14 @@ static PyObject* msiopendb(PyObject *obj, PyObject *args) 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); |