Skip to content

Commit c01943b

Browse files
committed
fix improper behavior
openssl_spki_export() is documented to return string, but it's obviously not achieved writing it to stdout :)
1 parent 3d7343f commit c01943b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ext/openssl/openssl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ PHP_FUNCTION(openssl_spki_export)
16371637

16381638
EVP_PKEY *pkey = NULL;
16391639
NETSCAPE_SPKI *spki = NULL;
1640-
BIO *out = BIO_new(BIO_s_mem());
1640+
BIO *out = NULL;
16411641

16421642
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &spkstr, &spkstr_len) == FAILURE) {
16431643
return;
@@ -1669,8 +1669,13 @@ PHP_FUNCTION(openssl_spki_export)
16691669
goto cleanup;
16701670
}
16711671

1672-
out = BIO_new_fp(stdout, BIO_NOCLOSE);
1673-
PEM_write_bio_PUBKEY(out, pkey);
1672+
out = BIO_new(BIO_s_mem());
1673+
if (out && PEM_write_bio_PUBKEY(out, pkey)) {
1674+
BUF_MEM *bio_buf;
1675+
1676+
BIO_get_mem_ptr(out, &bio_buf);
1677+
RETVAL_STRINGL((char *)bio_buf->data, bio_buf->length);
1678+
}
16741679
goto cleanup;
16751680

16761681
cleanup:

0 commit comments

Comments
 (0)