[Python-checkins] bpo-40645: restrict HMAC key len to INT_MAX (GH-20238)

Christian Heimes webhook-mailer at python.org
Tue May 19 18:35:59 EDT 2020


https://github.com/python/cpython/commit/aca4670ad695d4b01c7880fe3d0af817421945bd
commit: aca4670ad695d4b01c7880fe3d0af817421945bd
branch: master
author: Christian Heimes <christian at python.org>
committer: GitHub <noreply at github.com>
date: 2020-05-19T15:35:51-07:00
summary:

bpo-40645: restrict HMAC key len to INT_MAX (GH-20238)



Signed-off-by: Christian Heimes <christian at python.org>

Automerge-Triggered-By: @tiran

files:
M Modules/_hashopenssl.c

diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 36ad6a65d72cf..674bddc090a6f 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -1403,6 +1403,12 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
     HMACobject *self = NULL;
     int r;
 
+    if (key->len > INT_MAX) {
+        PyErr_SetString(PyExc_OverflowError,
+                        "key is too long.");
+        return NULL;
+    }
+
     if ((digestmod == NULL) || !strlen(digestmod)) {
         PyErr_SetString(
             PyExc_TypeError, "Missing required parameter 'digestmod'.");
@@ -1424,7 +1430,7 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
     r = HMAC_Init_ex(
         ctx,
         (const char*)key->buf,
-        key->len,
+        (int)key->len,
         digest,
         NULL /*impl*/);
     if (r == 0) {



More information about the Python-checkins mailing list