Skip to content
Closed
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
4 changes: 3 additions & 1 deletion src/cryptography/hazmat/backends/openssl/decode_asn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ def parse(self, backend, x509_obj):

def _decode_certificate_policies(backend, cp):
cp = backend._ffi.cast("Cryptography_STACK_OF_POLICYINFO *", cp)
cp = backend._ffi.gc(cp, backend._lib.CERTIFICATEPOLICIES_free)
cp = backend._ffi.gc(cp, lambda x: backend._lib.sk_POLICYINFO_pop_free(
x, backend._ffi.addressof(backend._lib._original_lib, "POLICYINFO_free")
))

num = backend._lib.sk_POLICYINFO_num(cp)
certificate_policies = []
Expand Down
30 changes: 25 additions & 5 deletions tests/hazmat/backends/test_openssl_memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
def main(argv):
import gc
import json
import traceback

import cffi

from cryptography.hazmat.bindings._openssl import ffi, lib

heap = {}

BACKTRACE_ENABLED = False
if BACKTRACE_ENABLED:
C_BACKTRACE_ENABLED = False
if C_BACKTRACE_ENABLED:
backtrace_ffi = cffi.FFI()
backtrace_ffi.cdef('''
int backtrace(void **, int);
Expand All @@ -54,10 +55,10 @@ def symbolize_backtrace(trace):
return stack
else:
def backtrace():
return None
return traceback.format_stack()

def symbolize_backtrace(trace):
return None
return trace

@ffi.callback("void *(size_t, const char *, int)")
def malloc(size, path, line):
Expand Down Expand Up @@ -210,7 +211,7 @@ class TestOpenSSLMemoryLeaks(object):
@pytest.mark.parametrize("path", [
"x509/PKITS_data/certs/ValidcRLIssuerTest28EE.crt",
])
def test_x509_certificate_extensions(self, path):
def test_der_x509_certificate_extensions(self, path):
assert_no_memory_leaks(textwrap.dedent("""
def func(path):
from cryptography import x509
Expand All @@ -226,6 +227,25 @@ def func(path):
cert.extensions
"""), [path])

@pytest.mark.parametrize("path", [
"x509/cryptography.io.pem",
])
def test_pem_x509_certificate_extensions(self, path):
assert_no_memory_leaks(textwrap.dedent("""
def func(path):
from cryptography import x509
from cryptography.hazmat.backends.openssl import backend

import cryptography_vectors

with cryptography_vectors.open_vector_file(path, "rb") as f:
cert = x509.load_pem_x509_certificate(
f.read(), backend
)

cert.extensions
"""), [path])

def test_x509_csr_extensions(self):
assert_no_memory_leaks(textwrap.dedent("""
def func():
Expand Down