Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash in :mod:`hmac` when the OpenSSL routine used by
:meth:`hmac.HMAC.update` or by :func:`hmac.new` fails on data larger
than 2048 bytes. Patch by Bénédikt Tran.
19 changes: 7 additions & 12 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,16 +1976,6 @@ hashlib_HMAC_get_hashlib_digest_name(HMACobject *self)
#endif
}

static int
hashlib_openssl_HMAC_update_once(PY_HMAC_CTX_TYPE *ctx, const Py_buffer *v)
{
if (!PY_HMAC_update(ctx, (const unsigned char *)v->buf, (size_t)v->len)) {
notify_smart_ssl_error_occurred_in(Py_STRINGIFY(PY_HMAC_update));
return -1;
}
return 0;
}

/* Thin wrapper around PY_HMAC_CTX_free that allows to pass a NULL 'ctx'. */
static inline void
hashlib_openssl_HMAC_CTX_free(PY_HMAC_CTX_TYPE *ctx)
Expand Down Expand Up @@ -2240,10 +2230,15 @@ _hmac_update(HMACobject *self, PyObject *obj)
GET_BUFFER_VIEW_OR_ERROR(obj, &view, return -1);
HASHLIB_EXTERNAL_INSTRUCTIONS_LOCKED(
self, view.len,
r = hashlib_openssl_HMAC_update_once(self->ctx, &view)
r = PY_HMAC_update(self->ctx, (const unsigned char *)view.buf,
(size_t)view.len)
);
PyBuffer_Release(&view);
return r;
if (r == 0) {
notify_smart_ssl_error_occurred_in(Py_STRINGIFY(PY_HMAC_update));
return -1;
}
return 0;
}

/*[clinic input]
Expand Down
Loading