summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-11 20:25:27 (GMT)
committerGitHub <noreply@github.com>2023-06-11 20:25:27 (GMT)
commit82ac2be6b386b7d106a36262f1aa960f638bde8d (patch)
tree1f5a43e85a5cd7a33e86427d0efdf4bb2397b592 /Modules
parented038953fc2316117a3eaad066b93b0348131fd8 (diff)
downloadcpython-82ac2be6b386b7d106a36262f1aa960f638bde8d.zip
cpython-82ac2be6b386b7d106a36262f1aa960f638bde8d.tar.gz
cpython-82ac2be6b386b7d106a36262f1aa960f638bde8d.tar.bz2
[3.12] gh-105375: Improve error handling in _ctypes (GH-105593) (#105663)
Prevent repeated PyLong_FromVoidPtr() from possibly overwriting the current exception. (cherry picked from commit e8998e46a7ce8ad336e0941a6da6e50cb88d1e47) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/callbacks.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c
index 8e694ba..d71297f 100644
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -479,12 +479,22 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid);
+ if (py_rclsid == NULL) {
+ Py_DECREF(func);
+ PyErr_WriteUnraisable(context ? context : Py_None);
+ return E_FAIL;
+ }
PyObject *py_riid = PyLong_FromVoidPtr((void *)riid);
+ if (py_riid == NULL) {
+ Py_DECREF(func);
+ Py_DECREF(py_rclsid);
+ PyErr_WriteUnraisable(context ? context : Py_None);
+ return E_FAIL;
+ }
PyObject *py_ppv = PyLong_FromVoidPtr(ppv);
- if (!py_rclsid || !py_riid || !py_ppv) {
- Py_XDECREF(py_rclsid);
- Py_XDECREF(py_riid);
- Py_XDECREF(py_ppv);
+ if (py_ppv == NULL) {
+ Py_DECREF(py_rclsid);
+ Py_DECREF(py_riid);
Py_DECREF(func);
PyErr_WriteUnraisable(context ? context : Py_None);
return E_FAIL;