Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-130151: Fix reference leaks in_hashlib.hmac_{new,digest}#130152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 9 commits intopython:mainfrompicnixz:fix/hmac/leak-130151
Feb 24, 2025
Merged
Changes from1 commit
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
PrevPrevious commit
NextNext commit
revert to ANSI C style
  • Loading branch information
@picnixz
picnixz committedFeb 22, 2025
commitc72c07e50e983d9c40ffe8cc04c7982a875f78be
34 changes: 21 additions & 13 deletionsModules/_hashopenssl.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1556,6 +1556,11 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
PyObject *digestmod)
/*[clinic end generated code: output=c20d9e4d9ed6d219 input=5f4071dcc7f34362]*/
{
PY_EVP_MD *digest = NULL;
HMAC_CTX *ctx = NULL;
HMACobject *self = NULL;
int r;

if (key->len > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"key is too long.");
Expand All@@ -1568,42 +1573,45 @@ _hashlib_hmac_new_impl(PyObject *module, Py_buffer *key, PyObject *msg_obj,
return NULL;
}

PY_EVP_MD *digest = py_digest_by_digestmod(module, digestmod, Py_ht_mac);
digest = py_digest_by_digestmod(module, digestmod, Py_ht_mac);
if (digest == NULL) {
return NULL;
}

HMAC_CTX *ctx = HMAC_CTX_new();
ctx = HMAC_CTX_new();
if (ctx == NULL) {
return PyErr_NoMemory();
PyErr_NoMemory();
goto error;
}

int ok= HMAC_Init_ex(ctx, key->buf, (int)key->len, digest, NULL);
r= HMAC_Init_ex(ctx, key->buf, (int)key->len, digest, NULL /* impl */);
PY_EVP_MD_free(digest);
if (!ok) {
HMAC_CTX_free(ctx);
if (!r) {
_setException(PyExc_ValueError, NULL);
return NULL;
goto error;
}

_hashlibstate *state = get_hashlib_state(module);
HMACobject *self = PyObject_New(HMACobject, state->HMACtype);
self = PyObject_New(HMACobject, state->HMACtype);
if (self == NULL) {
HMAC_CTX_free(ctx);
return NULL;
goto error;
}

self->ctx = ctx;
ctx = NULL; // 'ctx' is now owned by 'self'
HASHLIB_INIT_MUTEX(self);

if ((msg_obj != NULL) && (msg_obj != Py_None)) {
if (!_hmac_update(self, msg_obj)) {
Py_DECREF(self); // this also frees the HMAC context
return NULL;
goto error;
}
}

return (PyObject *)self;

error:
if (ctx) HMAC_CTX_free(ctx);
Py_XDECREF(self);
return NULL;
}

/* helper functions */
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp