summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2016-09-09 19:09:07 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2016-09-09 19:09:07 (GMT)
commit2a2becc1d10c1b4ae1d55720f5bdb54097fed1a4 (patch)
treec6b50c5f481e1aa6c75c26aa044df80f7e79f89c /PC
parent06aed90a1fe6fa48919ff0f1f39181e886df9efc (diff)
parent6ceda631af2717c271e0b5b2b05a036463764418 (diff)
downloadcpython-2a2becc1d10c1b4ae1d55720f5bdb54097fed1a4.zip
cpython-2a2becc1d10c1b4ae1d55720f5bdb54097fed1a4.tar.gz
cpython-2a2becc1d10c1b4ae1d55720f5bdb54097fed1a4.tar.bz2
Merge with 3.5
Diffstat (limited to 'PC')
-rw-r--r--PC/_msi.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/PC/_msi.c b/PC/_msi.c
index b66b18b..789b04f 100644
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -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);