Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free WOLFSSL_X509 from wolfSSL_get_peer_certificate() with wolfSSL >= 5.3.0 #188

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

cconlon
Copy link
Member

@cconlon cconlon commented Apr 17, 2024

Starting with wolfSSL 5.3.0 (wolfSSL/wolfssl@afca455), the wolfSSL_get_peer_certificate() API returns a new/duplicate WOLFSSL_X509 structure that needs to be explicitly freed with wolfSSL_X509_free().

Prior to wolfSSL 5.3.0, wolfSSL_get_peer_certificate() returned a pointer to internal memory that was freed automatically by normal native wolfSSL cleanup routines.

This shows up through some exploration with -fsanitize=address:

Indirect leak of 10 byte(s) in 1 object(s) allocated from:
    #0 0x7f5b9d305808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f5a404785af in wolfSSL_Malloc wolfcrypt/src/memory.c:352
    #2 0x7f5a405296b0 in CopyDecodedToX509 src/internal.c:12942
    #3 0x7f5a4066f818 in d2i_X509orX509REQ src/x509.c:3618
    #4 0x7f5a4066f9f5 in wolfSSL_X509_d2i_ex src/x509.c:3653
    #5 0x7f5a40690c0b in wolfSSL_X509_dup src/x509.c:13671
    #6 0x7f5a4063ccff in wolfSSL_get_peer_certificate src/ssl.c:13255
    #7 0x7f5a4085f20f in Java_com_wolfssl_WolfSSLSession_getPeerCertificate (wolfssljni/lib/libwolfssljni.so+0x2620f)
    #8 0x7f5b8972ffa6  (<unknown module>)

@cconlon cconlon assigned cconlon and JacobBarthelmeh and unassigned cconlon Apr 17, 2024
@JacobBarthelmeh JacobBarthelmeh merged commit e0d718e into wolfSSL:master Apr 17, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants