From 555cb5e13b215babb32cafb4d884acb1a462b44b Mon Sep 17 00:00:00 2001 From: Hung-ying Tyan Date: Fri, 8 Jun 2018 17:53:48 +0800 Subject: [PATCH] Fix free() in keymaster VTS The buffer is allocated by OPENSSL_malloc() in X509_NAME_oneline(name, nullptr, 0). Should be reclaimed by OPENSSL_free() instead of free(). The patch is provided by vink.shen@mediatek.corp-partner.google.com Bug: 109708231 Test: build pass Merged-In: I66a864e3e28905eebac2e7d3a4517d4d5aaa39df Change-Id: I66a864e3e28905eebac2e7d3a4517d4d5aaa39df (cherry picked from commit 79db3ec849c5f1142a0802dccfff6cbef564ff76) --- keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp | 7 ++++--- keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp index 3a181a96b7..7cdf253be8 100644 --- a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp +++ b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -322,11 +323,11 @@ bool verify_chain(const hidl_vec>& chain) { char* cert_sub = X509_NAME_oneline(X509_get_subject_name(key_cert.get()), nullptr, 0); EXPECT_STREQ("/CN=Android Keystore Key", cert_sub) << "Cert " << i << " has wrong subject. (Possibly b/38394614)"; - free(cert_sub); + OPENSSL_free(cert_sub); } - free(cert_issuer); - free(signer_subj); + OPENSSL_free(cert_issuer); + OPENSSL_free(signer_subj); if (dump_Attestations) std::cout << bin2hex(chain[i]) << std::endl; } diff --git a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp index 854c716881..450b3eb4e5 100644 --- a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp +++ b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -208,11 +209,11 @@ bool verify_chain(const hidl_vec>& chain) { char* cert_sub = X509_NAME_oneline(X509_get_subject_name(key_cert.get()), nullptr, 0); EXPECT_STREQ("/CN=Android Keystore Key", cert_sub) << "Cert " << i << " has wrong subject."; - free(cert_sub); + OPENSSL_free(cert_sub); } - free(cert_issuer); - free(signer_subj); + OPENSSL_free(cert_issuer); + OPENSSL_free(signer_subj); if (dump_Attestations) std::cout << bin2hex(chain[i]) << std::endl; }