[Python-checkins] cpython (3.4): Issue #21931: Fix error handling in msilib.FCICreate().

zach.ware python-checkins at python.org
Mon May 18 07:49:19 CEST 2015


https://hg.python.org/cpython/rev/41281737d71a
changeset:   96131:41281737d71a
branch:      3.4
parent:      96124:c79530e08985
user:        Zachary Ware <zachary.ware at gmail.com>
date:        Mon May 18 00:47:15 2015 -0500
summary:
  Issue #21931: Fix error handling in msilib.FCICreate().

Patch by Jeffrey Armstrong.

files:
  Misc/NEWS |   4 ++++
  PC/_msi.c |  15 ++++++++++++---
  2 files changed, 16 insertions(+), 3 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -48,6 +48,10 @@
 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
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -243,8 +243,13 @@
     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 @@
     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;
 }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list