Skip to content

Commit

Permalink
Fix some memory leaks in CRL.export (#1170)
Browse files Browse the repository at this point in the history
The bio was never freed, or used. sometime is never freed. While I'm
here, check return values for all the functions called here.
  • Loading branch information
davidben authored Dec 16, 2022
1 parent 1cafac4 commit 4aae795
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2502,23 +2502,26 @@ def export(
if digest_obj == _ffi.NULL:
raise ValueError("No such digest method")

bio = _lib.BIO_new(_lib.BIO_s_mem())
_openssl_assert(bio != _ffi.NULL)

# A scratch time object to give different values to different CRL
# fields
sometime = _lib.ASN1_TIME_new()
_openssl_assert(sometime != _ffi.NULL)
sometime = _ffi.gc(sometime, _lib.ASN1_TIME_free)

_lib.X509_gmtime_adj(sometime, 0)
_lib.X509_CRL_set1_lastUpdate(self._crl, sometime)
ret = _lib.X509_gmtime_adj(sometime, 0)
_openssl_assert(ret != _ffi.NULL)
ret = _lib.X509_CRL_set1_lastUpdate(self._crl, sometime)
_openssl_assert(ret == 1)

_lib.X509_gmtime_adj(sometime, days * 24 * 60 * 60)
_lib.X509_CRL_set1_nextUpdate(self._crl, sometime)
ret = _lib.X509_gmtime_adj(sometime, days * 24 * 60 * 60)
_openssl_assert(ret != _ffi.NULL)
ret = _lib.X509_CRL_set1_nextUpdate(self._crl, sometime)
_openssl_assert(ret == 1)

_lib.X509_CRL_set_issuer_name(
ret = _lib.X509_CRL_set_issuer_name(
self._crl, _lib.X509_get_subject_name(cert._x509)
)
_openssl_assert(ret == 1)

sign_result = _lib.X509_CRL_sign(self._crl, key._pkey, digest_obj)
if not sign_result:
Expand Down

0 comments on commit 4aae795

Please sign in to comment.