Skip to content

Commit 4b9e80e

Browse files
committed
Fix memory leak in php_openssl_load_all_certs_from_file() when push fails
1 parent 1931472 commit 4b9e80e

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

ext/openssl/openssl.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,29 +2291,25 @@ static STACK_OF(X509) *php_openssl_load_all_certs_from_file(
22912291
X509_INFO *xi;
22922292
char cert_path[MAXPATHLEN];
22932293

2294-
if(!(stack = sk_X509_new_null())) {
2295-
php_openssl_store_errors();
2296-
php_error_docref(NULL, E_ERROR, "Memory allocation failure");
2297-
goto end;
2298-
}
2299-
23002294
if (!php_openssl_check_path(cert_file, cert_file_len, cert_path, arg_num)) {
2301-
sk_X509_free(stack);
23022295
goto end;
23032296
}
23042297

23052298
if (!(in = BIO_new_file(cert_path, PHP_OPENSSL_BIO_MODE_R(PKCS7_BINARY)))) {
23062299
php_openssl_store_errors();
23072300
php_error_docref(NULL, E_WARNING, "Error opening the file, %s", cert_path);
2308-
sk_X509_free(stack);
23092301
goto end;
23102302
}
23112303

23122304
/* This loads from a file, a stack of x509/crl/pkey sets */
23132305
if (!(sk = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL))) {
23142306
php_openssl_store_errors();
23152307
php_error_docref(NULL, E_WARNING, "Error reading the file, %s", cert_path);
2316-
sk_X509_free(stack);
2308+
goto end;
2309+
}
2310+
2311+
if(!(stack = sk_X509_new_reserve(NULL, sk_X509_INFO_num(sk)))) {
2312+
php_openssl_store_errors();
23172313
goto end;
23182314
}
23192315

0 commit comments

Comments
 (0)