Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,10 @@ PHP_FUNCTION(openssl_pkcs12_read)

if (pkey) {
bio_out = BIO_new(BIO_s_mem());
if (!bio_out) {
goto cleanup;
}

if (PEM_write_bio_PrivateKey(bio_out, pkey, NULL, NULL, 0, 0, NULL)) {
BUF_MEM *bio_buf;
BIO_get_mem_ptr(bio_out, &bio_buf);
Expand All @@ -1544,23 +1548,27 @@ PHP_FUNCTION(openssl_pkcs12_read)
cert_num = sk_X509_num(ca);
if (ca && cert_num) {
array_init(&zextracerts);
bio_out = BIO_new(BIO_s_mem());
if (!bio_out) {
goto cleanup;
}

for (i = 0; i < cert_num; i++) {
zval zextracert;
X509* aCA = sk_X509_pop(ca);
if (!aCA) break;

bio_out = BIO_new(BIO_s_mem());
if (PEM_write_bio_X509(bio_out, aCA)) {
BUF_MEM *bio_buf;
BIO_get_mem_ptr(bio_out, &bio_buf);
ZVAL_STRINGL(&zextracert, bio_buf->data, bio_buf->length);
add_index_zval(&zextracerts, i, &zextracert);
}

BIO_reset(bio_out);
X509_free(aCA);
BIO_free(bio_out);
}
BIO_free(bio_out);

sk_X509_free(ca);
add_assoc_zval(zout, "extracerts", &zextracerts);
Expand Down Expand Up @@ -2806,33 +2814,41 @@ PHP_FUNCTION(openssl_pkcs7_read)
}

if (certs != NULL) {
bio_out = BIO_new(BIO_s_mem());
if (!bio_out) {
goto clean_exit;
}
for (i = 0; i < sk_X509_num(certs); i++) {
X509* ca = sk_X509_value(certs, i);

bio_out = BIO_new(BIO_s_mem());
if (bio_out && PEM_write_bio_X509(bio_out, ca)) {
if (PEM_write_bio_X509(bio_out, ca)) {
BUF_MEM *bio_buf;
BIO_get_mem_ptr(bio_out, &bio_buf);
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
add_index_zval(zout, i, &zcert);
}
BIO_free(bio_out);
BIO_reset(bio_out);
}
BIO_free(bio_out);
}

if (crls != NULL) {
bio_out = BIO_new(BIO_s_mem());
if (!bio_out) {
goto clean_exit;
}
for (i = 0; i < sk_X509_CRL_num(crls); i++) {
X509_CRL* crl = sk_X509_CRL_value(crls, i);

bio_out = BIO_new(BIO_s_mem());
if (bio_out && PEM_write_bio_X509_CRL(bio_out, crl)) {
if (PEM_write_bio_X509_CRL(bio_out, crl)) {
BUF_MEM *bio_buf;
BIO_get_mem_ptr(bio_out, &bio_buf);
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
add_index_zval(zout, i, &zcert);
}
BIO_free(bio_out);
BIO_reset(bio_out);
}
BIO_free(bio_out);
}

RETVAL_TRUE;
Expand Down Expand Up @@ -3467,33 +3483,43 @@ PHP_FUNCTION(openssl_cms_read)
}

if (certs != NULL) {
bio_out = BIO_new(BIO_s_mem());
if (!bio_out) {
goto clean_exit;
}

for (i = 0; i < sk_X509_num(certs); i++) {
X509* ca = sk_X509_value(certs, i);

bio_out = BIO_new(BIO_s_mem());
if (bio_out && PEM_write_bio_X509(bio_out, ca)) {
if (PEM_write_bio_X509(bio_out, ca)) {
BUF_MEM *bio_buf;
BIO_get_mem_ptr(bio_out, &bio_buf);
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
add_index_zval(zout, i, &zcert);
}
BIO_free(bio_out);
BIO_reset(bio_out);
}
BIO_free(bio_out);
}

if (crls != NULL) {
bio_out = BIO_new(BIO_s_mem());
if (!bio_out) {
goto clean_exit;
}

for (i = 0; i < sk_X509_CRL_num(crls); i++) {
X509_CRL* crl = sk_X509_CRL_value(crls, i);

bio_out = BIO_new(BIO_s_mem());
if (bio_out && PEM_write_bio_X509_CRL(bio_out, crl)) {
if (PEM_write_bio_X509_CRL(bio_out, crl)) {
BUF_MEM *bio_buf;
BIO_get_mem_ptr(bio_out, &bio_buf);
ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
add_index_zval(zout, i, &zcert);
}
BIO_free(bio_out);
BIO_reset(bio_out);
}
BIO_free(bio_out);
}

RETVAL_TRUE;
Expand Down
4 changes: 2 additions & 2 deletions ext/openssl/openssl_pwhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ZEND_EXTERN_MODULE_GLOBALS(openssl)
static inline zend_result get_options(zend_array *options, uint32_t *memlimit, uint32_t *iterlimit, uint32_t *threads)
{
zval *opt;
zend_long sthreads;

*iterlimit = PHP_OPENSSL_PWHASH_ITERLIMIT;
*memlimit = PHP_OPENSSL_PWHASH_MEMLIMIT;
Expand All @@ -76,8 +77,7 @@ static inline zend_result get_options(zend_array *options, uint32_t *memlimit, u
}
*iterlimit = siterlimit;
}
if ((opt = zend_hash_str_find(options, "threads", strlen("threads"))) && (zval_get_long(opt) != 1)) {
zend_long sthreads = zval_get_long(opt);
if ((opt = zend_hash_str_find(options, "threads", strlen("threads"))) && ((sthreads = zval_get_long(opt)) != 1)) {
if ((sthreads < PHP_OPENSSL_THREADS_MIN) || (sthreads > PHP_OPENSSL_THREADS_MAX)) {
zend_value_error("Invalid number of threads");
return FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion ext/openssl/xp_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ static unsigned char *php_openssl_alpn_protos_parse(unsigned short *outlen, cons
return NULL;
}

out = emalloc(strlen(in) + 1);
out = emalloc(len + 1);

for (i = 0; i <= len; ++i) {
if (i == len || in[i] == ',') {
Expand Down
Loading