From: Erlend E. Aasland Date: Sun, 11 Jun 2023 09:58:08 +0000 (+0200) Subject: gh-105375: Improve array.array exception handling (#105594) X-Git-Tag: v3.13.0a1~1800 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=35cff545db7c7912046c0ce5627db2e4d2b60f57;p=thirdparty%2FPython%2Fcpython.git gh-105375: Improve array.array exception handling (#105594) Fix a bug where 'tp_richcompare' could end up overwriting an exception. --- diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst new file mode 100644 index 000000000000..21aea1b0b408 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-06-09-21-46-52.gh-issue-105375.yrJelV.rst @@ -0,0 +1,2 @@ +Fix a bug in :class:`array.array` where an exception could end up being +overwritten. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 1a5993819b2e..8132689c66c0 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -767,10 +767,12 @@ array_richcompare(PyObject *v, PyObject *w, int op) k = 1; for (i = 0; i < Py_SIZE(va) && i < Py_SIZE(wa); i++) { vi = getarrayitem(v, i); + if (vi == NULL) { + return NULL; + } wi = getarrayitem(w, i); - if (vi == NULL || wi == NULL) { - Py_XDECREF(vi); - Py_XDECREF(wi); + if (wi == NULL) { + Py_DECREF(vi); return NULL; } k = PyObject_RichCompareBool(vi, wi, Py_EQ);