From: Zachary Ware Date: Mon, 18 May 2015 05:47:15 +0000 (-0500) Subject: Issue #21931: Fix error handling in msilib.FCICreate(). X-Git-Tag: v3.5.0b1~85^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a29e898cd9f8ca49008baba8e739422fd9276a8;p=thirdparty%2FPython%2Fcpython.git Issue #21931: Fix error handling in msilib.FCICreate(). Patch by Jeffrey Armstrong. --- diff --git a/Misc/NEWS b/Misc/NEWS index 2599b821d315..ed646ada53de 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -48,6 +48,10 @@ Core and Builtins Library ------- +- Issue #21931: msilib.FCICreate() now raises TypeError in the case of a bad + argument instead of a ValueError with a bogus FCI error number. + Patch by Jeffrey Armstrong. + - Issue #23796: peak and read1 methods of BufferedReader now raise ValueError if they called on a closed object. Patch by John Hergenroeder. diff --git a/PC/_msi.c b/PC/_msi.c index 6a99b40cda8d..86a594310644 100644 --- a/PC/_msi.c +++ b/PC/_msi.c @@ -243,8 +243,13 @@ static PyObject* fcicreate(PyObject* obj, PyObject* args) for (i=0; i < PyList_GET_SIZE(files); i++) { PyObject *item = PyList_GET_ITEM(files, i); char *filename, *cabname; - if (!PyArg_ParseTuple(item, "ss", &filename, &cabname)) - goto err; + + if (!PyArg_ParseTuple(item, "ss", &filename, &cabname)) { + PyErr_SetString(PyExc_TypeError, "FCICreate expects a list of tuples containing two strings"); + FCIDestroy(hfci); + return NULL; + } + if (!FCIAddFile(hfci, filename, cabname, FALSE, cb_getnextcabinet, cb_status, cb_getopeninfo, tcompTYPE_MSZIP)) @@ -260,7 +265,11 @@ static PyObject* fcicreate(PyObject* obj, PyObject* args) Py_INCREF(Py_None); return Py_None; err: - PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); /* XXX better error type */ + if(erf.fError) + PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); /* XXX better error type */ + else + PyErr_SetString(PyExc_ValueError, "FCI general error"); + FCIDestroy(hfci); return NULL; }