Skip to content

Commit

Permalink
fix improper behavior
Browse files Browse the repository at this point in the history
openssl_spki_export() is documented to return string, but it's
obviously not achieved writing it to stdout :)
  • Loading branch information
weltling committed Jul 3, 2015
1 parent 3d7343f commit c01943b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ PHP_FUNCTION(openssl_spki_export)

EVP_PKEY *pkey = NULL;
NETSCAPE_SPKI *spki = NULL;
BIO *out = BIO_new(BIO_s_mem());
BIO *out = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &spkstr, &spkstr_len) == FAILURE) {
return;
Expand Down Expand Up @@ -1669,8 +1669,13 @@ PHP_FUNCTION(openssl_spki_export)
goto cleanup;
}

out = BIO_new_fp(stdout, BIO_NOCLOSE);
PEM_write_bio_PUBKEY(out, pkey);
out = BIO_new(BIO_s_mem());
if (out && PEM_write_bio_PUBKEY(out, pkey)) {
BUF_MEM *bio_buf;

BIO_get_mem_ptr(out, &bio_buf);
RETVAL_STRINGL((char *)bio_buf->data, bio_buf->length);
}
goto cleanup;

cleanup:
Expand Down

0 comments on commit c01943b

Please sign in to comment.