Skip to content

Commit c4179dd

Browse files
jelle-openaiJelleZijlstra
authored andcommitted
gh-159739: Release SSL resources on error paths (GH-159745)
Free decoded subject alternative names when certificate conversion fails, and close the key log file if the BIO allocation fails. Backport to 3.15 and 3.14. (cherry picked from commit b2b0a33) Co-authored-by: Jelle Zijlstra <jelle@openai.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 065b5a5 commit c4179dd

3 files changed

Lines changed: 4 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix resource leaks in :mod:`ssl` when certificate conversion or key log setup
2+
fails.

‎Modules/_ssl.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ _get_peer_alt_names (_sslmodulestate *state, X509 *certificate) {
15121512

15131513

15141514
fail:
1515+
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
15151516
if (biobuf != NULL)
15161517
BIO_free(biobuf);
15171518

‎Modules/_ssl/debughelpers.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ _PySSLContext_set_keylog_filename(PyObject *op, PyObject *arg,
220220

221221
self->keylog_bio = BIO_new_fp(fp, BIO_CLOSE | BIO_FP_TEXT);
222222
if (self->keylog_bio == NULL) {
223+
fclose(fp);
223224
PyErr_SetString(get_state_ctx(self)->PySSLErrorObject,
224225
"Can't malloc memory for keylog file");
225226
return -1;

0 commit comments

Comments
 (0)