diff options
| author | Mark Shannon <mark@hotpy.org> | 2021-11-03 16:22:32 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-03 16:22:32 (GMT) |
| commit | acc89db9233abf4d903af9a7595a2ed7478fe7d3 (patch) | |
| tree | fb08e91bc2dab4db12daace28c778749a293a20f /Include/internal/pycore_runtime.h | |
| parent | 5a14929a6e4fab672e2f83a86773618e973b22a6 (diff) | |
| download | cpython-acc89db9233abf4d903af9a7595a2ed7478fe7d3.zip cpython-acc89db9233abf4d903af9a7595a2ed7478fe7d3.tar.gz cpython-acc89db9233abf4d903af9a7595a2ed7478fe7d3.tar.bz2 | |
bpo-45691: Make array of small ints static to fix use-after-free error. (GH-29366)
Diffstat (limited to 'Include/internal/pycore_runtime.h')
| -rw-r--r-- | Include/internal/pycore_runtime.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h index bcd710c..9df833c 100644 --- a/Include/internal/pycore_runtime.h +++ b/Include/internal/pycore_runtime.h @@ -11,6 +11,14 @@ extern "C" { #include "pycore_atomic.h" /* _Py_atomic_address */ #include "pycore_gil.h" // struct _gil_runtime_state +#define _PY_NSMALLPOSINTS 257 +#define _PY_NSMALLNEGINTS 5 + +// _PyLong_GetZero() and _PyLong_GetOne() must always be available +#if _PY_NSMALLPOSINTS < 2 +# error "_PY_NSMALLPOSINTS must be greater than 1" +#endif + /* ceval state */ struct _ceval_runtime_state { @@ -100,6 +108,13 @@ typedef struct pyruntimestate { unsigned long main_thread; + /* Small integers are preallocated in this array so that they + * can be shared. + * The integers that are preallocated are those in the range + *-_PY_NSMALLNEGINTS (inclusive) to _PY_NSMALLPOSINTS (not inclusive). + */ + PyLongObject small_ints[_PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS]; + #define NEXITFUNCS 32 void (*exitfuncs[NEXITFUNCS])(void); int nexitfuncs; |
