Skip to content

Commit 606c7a4

Browse files
committed
HSM: fix Engine init/free logics
After ENGINE_init(), there should be an ENGINE_finish(). Moreover, an ENGINE_free() can be performed after ENGINE_init() in any cases. No need to have both ENGINE_free() and ENGINE_finish(): doc: All functional references are released by calling ENGINE_finish() (which removes the implicit structural reference as well). Suggested-by: Jakub Zelenka <bukka@php.net>
1 parent 87d8f96 commit 606c7a4

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

ext/openssl/openssl.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,12 +960,12 @@ static ENGINE *php_openssl_make_pkcs11_engine(const bool warn) /* {{{ */
960960
}
961961
}
962962
if (!ENGINE_init(engine)) {
963-
ENGINE_free(engine);
964963
if (warn)
965964
php_error_docref(NULL, E_WARNING, "Cannot init PKCS11 engine");
966965
php_openssl_store_errors();
967966
return NULL;
968967
}
968+
ENGINE_free(engine);
969969

970970
return engine;
971971
}
@@ -1452,11 +1452,10 @@ X509 *php_openssl_x509_from_str(zend_string *cert_str) {
14521452
return NULL;
14531453

14541454
if (!ENGINE_ctrl_cmd(engine, "LOAD_CERT_CTRL", 0, &parms, NULL, force_login)) {
1455-
ENGINE_free(engine);
1455+
ENGINE_finish(engine);
14561456
php_openssl_store_errors();
14571457
return NULL;
14581458
}
1459-
ENGINE_free(engine);
14601459
ENGINE_finish(engine);
14611460
if (parms.cert == NULL) {
14621461
php_openssl_store_errors();
@@ -3642,7 +3641,6 @@ EVP_PKEY *php_openssl_pkey_from_zval(zval *val, int public_key, char *passphrase
36423641
if (public_key) {
36433642
if (engine) {
36443643
key = ENGINE_load_public_key(engine, Z_STRVAL_P(val), NULL, NULL);
3645-
ENGINE_free(engine);
36463644
ENGINE_finish(engine);
36473645
engine = NULL;
36483646
}
@@ -3671,7 +3669,6 @@ EVP_PKEY *php_openssl_pkey_from_zval(zval *val, int public_key, char *passphrase
36713669
/* we want the private key */
36723670
if (engine) {
36733671
key = ENGINE_load_private_key(engine, Z_STRVAL_P(val), NULL, NULL);
3674-
ENGINE_free(engine);
36753672
ENGINE_finish(engine);
36763673
engine = NULL;
36773674
} else {

0 commit comments

Comments
 (0)