]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-96187: Prevent _PyCode_GetExtra to return garbage for negative indexes (GH-96188)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 23 Aug 2022 11:02:19 +0000 (04:02 -0700)
committerGitHub <noreply@github.com>
Tue, 23 Aug 2022 11:02:19 +0000 (04:02 -0700)
(cherry picked from commit 16ebae4cd4029205d932751f26c719c6cb8a6e92)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Misc/NEWS.d/next/Core and Builtins/2022-08-22-21-33-28.gh-issue-96187.W_6SRG.rst [new file with mode: 0644]
Objects/codeobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-08-22-21-33-28.gh-issue-96187.W_6SRG.rst b/Misc/NEWS.d/next/Core and Builtins/2022-08-22-21-33-28.gh-issue-96187.W_6SRG.rst
new file mode 100644 (file)
index 0000000..fd194fa
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed a bug that caused ``_PyCode_GetExtra`` to return garbage for negative
+indexes. Patch by Pablo Galindo
index c0151434489ad1750ac2f1e4f2666d02fe5596c7..d7434ddefbc02670660165c0f1a116e9af37d265 100644 (file)
@@ -1337,7 +1337,7 @@ _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
     PyCodeObject *o = (PyCodeObject*) code;
     _PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) o->co_extra;
 
-    if (co_extra == NULL || co_extra->ce_size <= index) {
+    if (co_extra == NULL || index < 0 || co_extra->ce_size <= index) {
         *extra = NULL;
         return 0;
     }