-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-C-API
Description
If pid_t has the same size as int, PyLong_AsPid is defined as PyLong_AsLong. if the size of int is less than the size of long, there are values out of the C int range but in the C long range. Calling PyLong_AsPid() with such argument will not raise an exception, but casting the result out of the C int range to pid_t has undefined behavior.
Most non-Windows 64-bit platforms are affected.
The simplest solution is to define PyLong_AsPid as PyLong_AsInt. It only applicable in 3.13, because PyLong_AsInt is new in 3.13. In older versions there is _PyLong_AsInt, but it is declared in Include/cpython/longobject.h, not in Include/longobject.h.
Linked PRs
- gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms #117064
- [3.12] gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms (GH-117064) #117070
- [3.11] gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms (GH-117064) (GH-117070) #117075
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-C-API