Skip to content

Use OPENSSL_free for OpenSSL allocations to avoid crash - #41

Merged
JelteF merged 1 commit into
libusual:masterfrom
skmcgrail:variants
Sep 21, 2023
Merged

Use OPENSSL_free for OpenSSL allocations to avoid crash#41
JelteF merged 1 commit into
libusual:masterfrom
skmcgrail:variants

Conversation

@skmcgrail

@skmcgrail skmcgrail commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

Description

OpenSSL functions, like X509_NAME_oneline, returns pointers to memory allocations created using OPENSSL_malloc. The documentation for OpenSSL hints that such allocations should be freed using OPENSSL_free and not the standard free. For example:

OPENSSL_strdup(), OPENSSL_strndup() and OPENSSL_memdup() are like the equivalent C functions, except that memory is allocated by calling the OPENSSL_malloc() and should be released by calling OPENSSL_free().

In OpenSSL forks like BoringSSL and AWS-LC, OPENSSL_malloc returns a pointer that can't be freed by free, and when attempted will cause a panic:

#0  0x0000ffff8e367c9c in free () from /lib64/libc.so.6
#1  0x000000000043a168 in tls_free_conninfo (conninfo=0x272fbea0) at lib/usual/tls/tls_conninfo.c:193
#2  0x0000000000436dc4 in tls_reset (ctx=ctx@entry=0x272f4bb0) at lib/usual/tls/tls.c:519
#3  0x0000000000436e58 in tls_free (ctx=0x272f4bb0) at lib/usual/tls/tls.c:494

This PR updates tls_free_conninfo to properly free the issuer and subject information in order to improve compatibility with the OpenSSL forks.

@JelteF
JelteF merged commit 490d96e into libusual:master Sep 21, 2023
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