bpo-34987: Fix a possible null pointer dereference in _pickle.c's save_reduce(). (GH-9886)
(cherry picked from commit 25d389789c59a52a31770f7c50ce9e02a8909190)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index a1a90bd..57bb771 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -3838,7 +3838,10 @@
if (obj != NULL) {
obj_class = get_class(obj);
- p = obj_class != cls; /* true iff a problem */
+ if (obj_class == NULL) {
+ return -1;
+ }
+ p = obj_class != cls;
Py_DECREF(obj_class);
if (p) {
PyErr_SetString(st->PicklingError, "args[0] from "