FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-159811: Raise OpenSSL errors in `_hashlib.HASH` after re-attaching the thread state (GH-159817) by miss-islington · Pull Request #159927 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .c  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.
15 changes: 12 additions & 3 deletions Modules/_hashopenssl.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,12 @@ new_hash_object(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
_hashlib_HASH_hash(HASHobject *self, const void *vp, Py_ssize_t len)
{
Expand All @@ -857,7 +863,6 @@ _hashlib_HASH_hash(HASHobject *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_in(Py_STRINGIFY(EVP_DigestUpdate));
return -1;
}
len -= process;
Expand Down Expand Up @@ -990,7 +995,11 @@ _hashlib_HASH_update_impl(HASHobject *self, PyObject *obj)
result = _hashlib_HASH_hash(self, view.buf, view.len)
);
PyBuffer_Release(&view);
return result < 0 ? NULL : Py_None;
if (result < 0) {
notify_ssl_error_occurred_in(Py_STRINGIFY(EVP_DigestUpdate));
return NULL;
}
Py_RETURN_NONE;
}

static PyMethodDef HASH_methods[] = {
Expand Down Expand Up @@ -1304,7 +1313,7 @@ _hashlib_HASH(_hashlibstate *state, const char *digestname, PyObject *data_obj,
result = _hashlib_HASH_hash(self, view.buf, view.len)
);
if (result == -1) {
assert(PyErr_Occurred());
notify_ssl_error_occurred_in(Py_STRINGIFY(EVP_DigestUpdate));
Py_CLEAR(self);
goto exit;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL