summaryrefslogtreecommitdiffstats
path: root/Modules/_sre
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-10 10:55:21 (GMT)
committerGitHub <noreply@github.com>2023-10-10 10:55:21 (GMT)
commitc1e8e90915e38604175e20e36a24fe45249cdc33 (patch)
tree4c9afd5aadf26c4887092ce7be9825a8c3e3a252 /Modules/_sre
parent55d607683f85367e503ee34b85bc3b9c1a782552 (diff)
downloadcpython-c1e8e90915e38604175e20e36a24fe45249cdc33.zip
cpython-c1e8e90915e38604175e20e36a24fe45249cdc33.tar.gz
cpython-c1e8e90915e38604175e20e36a24fe45249cdc33.tar.bz2
[3.12] gh-110590: Fix a bug where _sre.compile would overwrite exceptions (GH-110591) (#110613)
TypeError would be overwritten by OverflowError if 'code' param contained non-ints. (cherry picked from commit 344d3a222a7864f8157773749bdd77d1c9dfc1e6) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Modules/_sre')
-rw-r--r--Modules/_sre/sre.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c
index 2f1c732..ace2e9b 100644
--- a/Modules/_sre/sre.c
+++ b/Modules/_sre/sre.c
@@ -1462,6 +1462,9 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
for (i = 0; i < n; i++) {
PyObject *o = PyList_GET_ITEM(code, i);
unsigned long value = PyLong_AsUnsignedLong(o);
+ if (value == (unsigned long)-1 && PyErr_Occurred()) {
+ break;
+ }
self->code[i] = (SRE_CODE) value;
if ((unsigned long) self->code[i] != value) {
PyErr_SetString(PyExc_OverflowError,