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
4 changes: 2 additions & 2 deletions ext/openssl/openssl_pwhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ PHP_FUNCTION(openssl_password_hash)
Z_PARAM_ARRAY_HT(options)
ZEND_PARSE_PARAMETERS_END();

if (strcmp(ZSTR_VAL(algo), "argon2i") && strcmp(ZSTR_VAL(algo), "argon2id")) {
if (!zend_string_equals_literal(algo, "argon2i") && !zend_string_equals_literal(algo, "argon2id")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be useful to add tests with algorithms values containing nul bytes for ex.

zend_argument_value_error(1, "must be a valid password openssl hashing algorithm");
RETURN_THROWS();
}
Expand All @@ -355,7 +355,7 @@ PHP_FUNCTION(openssl_password_verify)
Z_PARAM_STR(digest)
ZEND_PARSE_PARAMETERS_END();

if (strcmp(ZSTR_VAL(algo), "argon2i") && strcmp(ZSTR_VAL(algo), "argon2id")) {
if (!zend_string_equals_literal(algo, "argon2i") && !zend_string_equals_literal(algo, "argon2id")) {
zend_argument_value_error(1, "must be a valid password openssl hashing algorithm");
RETURN_THROWS();
}
Expand Down
33 changes: 33 additions & 0 deletions ext/openssl/tests/password_algo_null_bytes.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
OpenSSL password functions reject algorithm names containing NUL bytes
--EXTENSIONS--
openssl
--SKIPIF--
<?php
if (!function_exists('openssl_password_hash')) {
die('skip OpenSSL Argon2 support not available');
}
?>
--FILE--
<?php

foreach (["argon2i\0foo", "argon2id\0foo"] as $algo) {
try {
openssl_password_hash($algo, "secret");
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
openssl_password_verify($algo, "secret", "digest");
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
}

?>
--EXPECT--
openssl_password_hash(): Argument #1 ($algo) must be a valid password openssl hashing algorithm
openssl_password_verify(): Argument #1 ($algo) must be a valid password openssl hashing algorithm
openssl_password_hash(): Argument #1 ($algo) must be a valid password openssl hashing algorithm
openssl_password_verify(): Argument #1 ($algo) must be a valid password openssl hashing algorithm
Loading