]> granicus.if.org Git - php/commitdiff
Fix EC_KEY memory leaks
authorJakub Zelenka <bukka@php.net>
Sun, 30 Oct 2016 18:58:11 +0000 (18:58 +0000)
committerJakub Zelenka <bukka@php.net>
Sun, 30 Oct 2016 18:58:11 +0000 (18:58 +0000)
It was caused by using of EVP_PKEY_get1_EC_KEY which increments an EC_KEY
reference. The fix it we simply use EVP_PKEY_get0_EC_KEY.

ext/openssl/openssl.c

index ab58f47d0f48f3fee70a0f09c1cfd0c9fb50f2a5..ce9a5019d0155d25323ba973dd289c44e723b24d 100644 (file)
@@ -4370,7 +4370,7 @@ PHP_FUNCTION(openssl_pkey_export_to_file)
                switch (EVP_PKEY_base_id(key)) {
 #ifdef HAVE_EVP_PKEY_EC
                        case EVP_PKEY_EC:
-                               pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get1_EC_KEY(key), cipher, (unsigned char *)passphrase, (int)passphrase_len, NULL, NULL);
+                               pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(key), cipher, (unsigned char *)passphrase, (int)passphrase_len, NULL, NULL);
                                break;
 #endif
                        default:
@@ -4444,7 +4444,7 @@ PHP_FUNCTION(openssl_pkey_export)
                switch (EVP_PKEY_base_id(key)) {
 #ifdef HAVE_EVP_PKEY_EC
                        case EVP_PKEY_EC:
-                               pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get1_EC_KEY(key), cipher, (unsigned char *)passphrase, (int)passphrase_len, NULL, NULL);
+                               pem_write = PEM_write_bio_ECPrivateKey(bio_out, EVP_PKEY_get0_EC_KEY(key), cipher, (unsigned char *)passphrase, (int)passphrase_len, NULL, NULL);
                                break;
 #endif
                        default:
@@ -4656,7 +4656,7 @@ PHP_FUNCTION(openssl_pkey_get_details)
                                ASN1_OBJECT *obj;
                                // openssl recommends a buffer length of 80
                                char oir_buf[80];
-                               const EC_KEY *ec_key = EVP_PKEY_get1_EC_KEY(pkey);
+                               const EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(pkey);
                                BIGNUM *x = BN_new();
                                BIGNUM *y = BN_new();
                                const BIGNUM *d;