Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a89dbf8

Browse filesBrowse files
erlend-aaslandpull[bot]
authored andcommitted
gh-105375: Improve error handling in _ctypes (#105593)
Prevent repeated PyLong_FromVoidPtr() from possibly overwriting the current exception.
1 parent 5645e74 commit a89dbf8
Copy full SHA for a89dbf8

File tree

Expand file treeCollapse file tree

2 files changed

+15
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-4
lines changed
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bugs in :mod:`_ctypes` where exceptions could end up being overwritten.

‎Modules/_ctypes/callbacks.c

Copy file name to clipboardExpand all lines: Modules/_ctypes/callbacks.c
+14-4Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,22 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
479479

480480
{
481481
PyObject *py_rclsid = PyLong_FromVoidPtr((void *)rclsid);
482+
if (py_rclsid == NULL) {
483+
Py_DECREF(func);
484+
PyErr_WriteUnraisable(context ? context : Py_None);
485+
return E_FAIL;
486+
}
482487
PyObject *py_riid = PyLong_FromVoidPtr((void *)riid);
488+
if (py_riid == NULL) {
489+
Py_DECREF(func);
490+
Py_DECREF(py_rclsid);
491+
PyErr_WriteUnraisable(context ? context : Py_None);
492+
return E_FAIL;
493+
}
483494
PyObject *py_ppv = PyLong_FromVoidPtr(ppv);
484-
if (!py_rclsid || !py_riid || !py_ppv) {
485-
Py_XDECREF(py_rclsid);
486-
Py_XDECREF(py_riid);
487-
Py_XDECREF(py_ppv);
495+
if (py_ppv == NULL) {
496+
Py_DECREF(py_rclsid);
497+
Py_DECREF(py_riid);
488498
Py_DECREF(func);
489499
PyErr_WriteUnraisable(context ? context : Py_None);
490500
return E_FAIL;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.