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:`hashlib` when the OpenSSL routine used by
:meth:`hash.update() <hashlib.hash.update>` or by hash object constructors
fails on data larger than 2048 bytes. Patch by Bénédikt Tran.
13 changes: 10 additions & 3 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ newEVPobject(PyTypeObject *type)
return retval;
}

/*
* Update the digest context of 'self' with 'len' bytes from 'vp'.
*
* Return 0 on success and -1 if EVP_DigestUpdate() failed. No exception
* is set, so that this can be called without an attached thread state.
*/
static int
EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
{
Expand All @@ -527,7 +533,6 @@ EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len)
else
process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int);
if (!EVP_DigestUpdate(self->ctx, (const void*)cp, process)) {
notify_ssl_error_occurred();
return -1;
}
len -= process;
Expand Down Expand Up @@ -694,8 +699,10 @@ EVP_update_impl(EVPobject *self, PyObject *obj)

PyBuffer_Release(&view);

if (result == -1)
if (result == -1) {
notify_ssl_error_occurred();
return NULL;
}
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -1000,7 +1007,7 @@ _hashlib_HASH(PyObject *module, const char *digestname, PyObject *data_obj,
result = EVP_hash(self, view.buf, view.len);
}
if (result == -1) {
assert(PyErr_Occurred());
notify_ssl_error_occurred();
Py_CLEAR(self);
goto exit;
}
Expand Down
Loading