[Python-checkins] (no subject)

Stéphane Wirtel webhook-mailer at python.org
Thu Sep 12 09:30:51 EDT 2019




To: python-checkins at python.org
Subject: bpo-38132: Check EVP_DigestUpdate for error (GH-16041)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

https://github.com/python/cpython/commit/8c74574e0aaf1a00719fbc9acbdc27a39235=
20aa
commit: 8c74574e0aaf1a00719fbc9acbdc27a3923520aa
branch: master
author: Christian Heimes <christian at python.org>
committer: St=C3=A9phane Wirtel <stephane at wirtel.be>
date: 2019-09-12T14:30:47+01:00
summary:

bpo-38132: Check EVP_DigestUpdate for error (GH-16041)

files:
M Modules/_hashopenssl.c

diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 798317fb58b9..bea7e5ed3123 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -96,7 +96,7 @@ newEVPobject(void)
     return retval;
 }
=20
-static void
+static int
 EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
 {
     unsigned int process;
@@ -108,11 +108,12 @@ EVP_hash(EVPobject *self, const void *vp, Py_ssize_t le=
n)
             process =3D Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int);
         if (!EVP_DigestUpdate(self->ctx, (const void*)cp, process)) {
             _setException(PyExc_ValueError);
-            break;
+            return -1;
         }
         len -=3D process;
         cp +=3D process;
     }
+    return 0;
 }
=20
 /* Internal methods for a hash object */
@@ -243,6 +244,7 @@ static PyObject *
 EVP_update(EVPobject *self, PyObject *obj)
 /*[clinic end generated code: output=3Dec1d55ed2432e966 input=3D9b30ec848f01=
5501]*/
 {
+    int result;
     Py_buffer view;
=20
     GET_BUFFER_VIEW_OR_ERROUT(obj, &view);
@@ -255,14 +257,17 @@ EVP_update(EVPobject *self, PyObject *obj)
     if (self->lock !=3D NULL) {
         Py_BEGIN_ALLOW_THREADS
         PyThread_acquire_lock(self->lock, 1);
-        EVP_hash(self, view.buf, view.len);
+        result =3D EVP_hash(self, view.buf, view.len);
         PyThread_release_lock(self->lock);
         Py_END_ALLOW_THREADS
     } else {
-        EVP_hash(self, view.buf, view.len);
+        result =3D EVP_hash(self, view.buf, view.len);
     }
=20
     PyBuffer_Release(&view);
+
+    if (result =3D=3D -1)
+        return NULL;
     Py_RETURN_NONE;
 }
=20
@@ -396,6 +401,7 @@ static PyObject *
 EVPnew(const EVP_MD *digest,
        const unsigned char *cp, Py_ssize_t len)
 {
+    int result =3D 0;
     EVPobject *self;
=20
     if (!digest) {
@@ -415,10 +421,14 @@ EVPnew(const EVP_MD *digest,
     if (cp && len) {
         if (len >=3D HASHLIB_GIL_MINSIZE) {
             Py_BEGIN_ALLOW_THREADS
-            EVP_hash(self, cp, len);
+            result =3D EVP_hash(self, cp, len);
             Py_END_ALLOW_THREADS
         } else {
-            EVP_hash(self, cp, len);
+            result =3D EVP_hash(self, cp, len);
+        }
+        if (result =3D=3D -1) {
+            Py_DECREF(self);
+            return NULL;
         }
     }
=20



More information about the Python-checkins mailing list