Skip to content
Merged
13 changes: 6 additions & 7 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3968,6 +3968,7 @@ PHP_FUNCTION(openssl_sign)
mdtype = php_openssl_get_evp_md_from_algo(method_long);
}
if (!mdtype && (!can_default_digest || method_long != 0)) {
EVP_PKEY_free(pkey);
php_error_docref(NULL, E_WARNING, "Unknown digest algorithm");
RETURN_FALSE;
}
Expand Down Expand Up @@ -4471,17 +4472,15 @@ PHP_FUNCTION(openssl_random_pseudo_bytes)
RETURN_THROWS();
}

if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_FALSE(zstrong_result_returned);
}

if ((buffer = php_openssl_random_pseudo_bytes(buffer_length))) {
ZSTR_VAL(buffer)[buffer_length] = 0;
RETVAL_NEW_STR(buffer);
}

if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_TRUE(zstrong_result_returned);
if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_TRUE(zstrong_result_returned);
}
} else if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_FALSE(zstrong_result_returned);
}
}
/* }}} */
3 changes: 1 addition & 2 deletions ext/openssl/openssl_backend_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,11 +2123,10 @@ PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_le
PHP_OPENSSL_CHECK_LONG_TO_INT_NULL_RETURN(buffer_length, length);
PHP_OPENSSL_RAND_ADD_TIME();
if (RAND_bytes((unsigned char*)ZSTR_VAL(buffer), (int)buffer_length) <= 0) {
php_openssl_store_errors();
zend_string_release_ex(buffer, 0);
zend_throw_exception(zend_ce_exception, "Error reading from source device", 0);
return NULL;
} else {
php_openssl_store_errors();
}

return buffer;
Expand Down
18 changes: 18 additions & 0 deletions ext/openssl/tests/openssl_sign_invalid_algorithm.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
openssl_sign: invalid algorithm
--EXTENSIONS--
openssl
--FILE--
<?php
$dir = __DIR__;
$file_pub = $dir . '/bug37820cert.pem';
$file_key = $dir . '/bug37820key.pem';

$priv_key = file_get_contents($file_key);
$priv_key_id = openssl_get_privatekey($priv_key);

$data = "some custom data";
openssl_sign($data, $signature, $priv_key_id, "invalid algo");
?>
--EXPECTF--
Warning: openssl_sign(): Unknown digest algorithm in %s on line %d
1 change: 1 addition & 0 deletions ext/standard/iptc.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ PHP_FUNCTION(iptcembed)

if (spool < 2) {
if (zend_fstat(fileno(fp), &sb) != 0) {
fclose(fp);
RETURN_FALSE;
}

Expand Down
Loading