Skip to content
Closed
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
34 changes: 34 additions & 0 deletions ext/phar/tests/openssl_sign_invalid_polyfill_return_value.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
openssl_sign() polyfill with wrong return value
--EXTENSIONS--
phar
--SKIPIF--
<?php
if (getenv('SKIP_SLOW_TESTS')) die('skip');
if (function_exists('openssl_sign')) die('skip requires openssl disabled for mocking purposes');
?>
--INI--
phar.require_hash=0
--FILE--
<?php
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.tar';

function openssl_sign() {
return str_repeat('foobar', random_int(1, 1));
}

$phar = new PharData($fname);
$phar->setSignatureAlgorithm(Phar::OPENSSL, "randomcrap");
try {
$phar->addEmptyDir('blah');
} catch (PharException $e) {
echo $e->getMessage();
}

?>
--CLEAN--
<?php
@unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar');
?>
--EXPECTF--
phar error: unable to write signature to tar-based phar: unable to write phar "%s" with requested openssl signature
4 changes: 3 additions & 1 deletion ext/phar/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,6 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
zval_ptr_dtor_str(&zp[2]);

switch (Z_TYPE(retval)) {
default:
case IS_LONG:
zval_ptr_dtor(&zp[1]);
if (1 == Z_LVAL(retval)) {
Expand All @@ -1483,6 +1482,9 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, zend_off_t
*signature_len = Z_STRLEN(zp[1]);
zval_ptr_dtor(&zp[1]);
return SUCCESS;
default:
zval_ptr_dtor(&retval);
ZEND_FALLTHROUGH;
case IS_FALSE:
zval_ptr_dtor(&zp[1]);
return FAILURE;
Expand Down
Loading