bpo-38942: Fix possible assertion failures in csv.Dialect()

This commit is contained in:
Zackery Spytz 2019-11-29 13:22:34 -07:00
parent bea33f5e1d
commit 323de6506d
2 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1 @@
Fix possible assertion failures when creating a :class:`csv.Dialect` object.

View File

@ -394,8 +394,14 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
Py_XINCREF(strict); Py_XINCREF(strict);
if (dialect != NULL) { if (dialect != NULL) {
#define DIALECT_GETATTR(v, n) \ #define DIALECT_GETATTR(v, n) \
if (v == NULL) \ if (v == NULL) { \
v = PyObject_GetAttrString(dialect, n) if ((v = PyObject_GetAttrString(dialect, n)) == NULL) { \
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { \
goto err; \
} \
PyErr_Clear(); \
} \
}
DIALECT_GETATTR(delimiter, "delimiter"); DIALECT_GETATTR(delimiter, "delimiter");
DIALECT_GETATTR(doublequote, "doublequote"); DIALECT_GETATTR(doublequote, "doublequote");
DIALECT_GETATTR(escapechar, "escapechar"); DIALECT_GETATTR(escapechar, "escapechar");
@ -404,7 +410,6 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
DIALECT_GETATTR(quoting, "quoting"); DIALECT_GETATTR(quoting, "quoting");
DIALECT_GETATTR(skipinitialspace, "skipinitialspace"); DIALECT_GETATTR(skipinitialspace, "skipinitialspace");
DIALECT_GETATTR(strict, "strict"); DIALECT_GETATTR(strict, "strict");
PyErr_Clear();
} }
/* check types and convert to C values */ /* check types and convert to C values */