Skip to content

Commit 7dd08a7

Browse files
Copilotmarkt-asf
andcommitted
Free server certificate (x509cert) after SSL_CTX_use_certificate in OpenSSLContext
SSL_CTX_use_certificate makes an internal copy, so the caller should free the original. This is the same class of bug fixed by commit 8ef5efc for client CA certificates after SSL_CTX_add_client_CA. X509_free is added on: - early return when private key parsing fails (x509cert already allocated) - error path when SSL_CTX_use_certificate fails - success path after SSL_CTX_use_certificate (copy already made internally) Co-authored-by: markt-asf <markt@apache.org>
1 parent df55361 commit 7dd08a7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,15 @@ public boolean addCertificate(SSLHostConfigCertificate certificate, Arena localA
12481248
PEM_read_bio_PrivateKey(keyBIO, MemorySegment.NULL, MemorySegment.NULL, MemorySegment.NULL);
12491249
if (MemorySegment.NULL.equals(privateKeyAddress)) {
12501250
logLastError("openssl.errorLoadingPrivateKey");
1251+
X509_free(x509cert);
12511252
return false;
12521253
}
12531254
if (SSL_CTX_use_certificate(state.sslCtx, x509cert) <= 0) {
12541255
logLastError("openssl.errorLoadingCertificate");
1256+
X509_free(x509cert);
12551257
return false;
12561258
}
1259+
X509_free(x509cert);
12571260
if (SSL_CTX_use_PrivateKey(state.sslCtx, privateKeyAddress) <= 0) {
12581261
logLastError("openssl.errorLoadingPrivateKey");
12591262
return false;

0 commit comments

Comments
 (0)