system/security/softkeymaster: don't pass a structure into |d2i_PrivateKey|.
Some OpenSSL parsing functions have, historically, allowed a structure
to be passed in to reuse that memory. There have been many bugs arising
from this corner case and it's generally best to avoid it.
This change just passes in NULL because a new structure was being
allocated anyway. Also, the API didn't guarantee that the memory would
always be reused – code had to check the updated pointer, which this
didn't do. So it might have broken in the future.
Change-Id: Iba98f9d11ece457cf6b66e2637bb8cb23f5930d2
diff --git a/softkeymaster/keymaster_openssl.cpp b/softkeymaster/keymaster_openssl.cpp
index 6f31195..927b4a6 100644
--- a/softkeymaster/keymaster_openssl.cpp
+++ b/softkeymaster/keymaster_openssl.cpp
@@ -208,17 +208,11 @@
return NULL;
}
- Unique_EVP_PKEY pkey(EVP_PKEY_new());
+ Unique_EVP_PKEY pkey(d2i_PrivateKey(type, nullptr, &p, privateLen));
if (pkey.get() == NULL) {
logOpenSSLError("unwrap_key");
return NULL;
}
- EVP_PKEY* tmp = pkey.get();
-
- if (d2i_PrivateKey(type, &tmp, &p, privateLen) == NULL) {
- logOpenSSLError("unwrap_key");
- return NULL;
- }
return pkey.release();
}