summaryrefslogtreecommitdiff
path: root/Modules/_pickle.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-09-01 12:03:39 +0300
committerGitHub <noreply@github.com>2019-09-01 12:03:39 +0300
commit41c57b335330ff48af098d47e379e0f9ba09d233 (patch)
tree15cdef099182eddb04b2276dc51375b8faf28278 /Modules/_pickle.c
parentf02ea6225bc3b71bd5fe66224d199a6e3e23b14d (diff)
downloadcpython-git-41c57b335330ff48af098d47e379e0f9ba09d233.tar.gz
bpo-37994: Fix silencing all errors if an attribute lookup fails. (GH-15630)
Only AttributeError should be silenced.
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r--Modules/_pickle.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 0c53f2e186..9e82d145cc 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4383,7 +4383,6 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
_Py_IDENTIFIER(__reduce__);
_Py_IDENTIFIER(__reduce_ex__);
-
/* XXX: If the __reduce__ method is defined, __reduce_ex__ is
automatically defined as __reduce__. While this is convenient, this
make it impossible to know which method was actually called. Of
@@ -4404,14 +4403,15 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
}
}
else {
- PickleState *st = _Pickle_GetGlobalState();
-
/* Check for a __reduce__ method. */
- reduce_func = _PyObject_GetAttrId(obj, &PyId___reduce__);
+ if (_PyObject_LookupAttrId(obj, &PyId___reduce__, &reduce_func) < 0) {
+ goto error;
+ }
if (reduce_func != NULL) {
reduce_value = PyObject_CallNoArgs(reduce_func);
}
else {
+ PickleState *st = _Pickle_GetGlobalState();
PyErr_Format(st->PicklingError,
"can't pickle '%.200s' object: %R",
type->tp_name, obj);
@@ -6446,7 +6446,9 @@ do_append(UnpicklerObject *self, Py_ssize_t x)
PyObject *extend_func;
_Py_IDENTIFIER(extend);
- extend_func = _PyObject_GetAttrId(list, &PyId_extend);
+ if (_PyObject_LookupAttrId(list, &PyId_extend, &extend_func) < 0) {
+ return -1;
+ }
if (extend_func != NULL) {
slice = Pdata_poplist(self->stack, x);
if (!slice) {
@@ -6466,7 +6468,6 @@ do_append(UnpicklerObject *self, Py_ssize_t x)
/* Even if the PEP 307 requires extend() and append() methods,
fall back on append() if the object has no extend() method
for backward compatibility. */
- PyErr_Clear();
append_func = _PyObject_GetAttrId(list, &PyId_append);
if (append_func == NULL)
return -1;