diff options
author | T. Wouters <thomas@python.org> | 2021-07-13 22:56:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-13 22:56:45 (GMT) |
commit | 0093876328afa330224c9d887c18dee0b3117852 (patch) | |
tree | 9bd8a30bb6577ab1a973fa68b078ee5e6627f873 /Modules | |
parent | 054e9c84ac7c394941bba3ea1829d14dce1243fc (diff) | |
download | cpython-0093876328afa330224c9d887c18dee0b3117852.zip cpython-0093876328afa330224c9d887c18dee0b3117852.tar.gz cpython-0093876328afa330224c9d887c18dee0b3117852.tar.bz2 |
bpo-44630: Fix assertion errors in csv module (GH-27127)
Fix incorrect handling of exceptions when interpreting dialect objects in
the csv module. Not clearing exceptions between calls to
PyObject_GetAttrString() causes assertion failures in pydebug mode (or with
assertions enabled).
Add a minimal test that would've caught this (passing None as dialect, or
any object that isn't a csv.Dialect subclass, which the csv module allows
and caters to, even though it is not documented.) In pydebug mode, the test
triggers the assertion failure in the old code.
Contributed-By: T. Wouters [Google]
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_csv.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c index 78855b8..3109fd1 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -421,9 +421,14 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) Py_XINCREF(skipinitialspace); Py_XINCREF(strict); if (dialect != NULL) { -#define DIALECT_GETATTR(v, n) \ - if (v == NULL) \ - v = PyObject_GetAttrString(dialect, n) +#define DIALECT_GETATTR(v, n) \ + do { \ + if (v == NULL) { \ + v = PyObject_GetAttrString(dialect, n); \ + if (v == NULL) \ + PyErr_Clear(); \ + } \ + } while (0) DIALECT_GETATTR(delimiter, "delimiter"); DIALECT_GETATTR(doublequote, "doublequote"); DIALECT_GETATTR(escapechar, "escapechar"); @@ -432,7 +437,6 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) DIALECT_GETATTR(quoting, "quoting"); DIALECT_GETATTR(skipinitialspace, "skipinitialspace"); DIALECT_GETATTR(strict, "strict"); - PyErr_Clear(); } /* check types and convert to C values */ |