Skip to content

Sodium warning to Exception #5880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
49 changes: 28 additions & 21 deletions ext/sodium/libsodium.c
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,10 @@ PHP_FUNCTION(sodium_crypto_pwhash)
zend_argument_error(sodium_exception_ce, 1, "is too large");
RETURN_THROWS();
}
if (passwd_len == 0) {
zend_argument_error(sodium_exception_ce, 2, "cannot be empty");
RETURN_THROWS();
}
if (passwd_len >= 0xffffffff) {
zend_argument_error(sodium_exception_ce, 2, "is too long");
RETURN_THROWS();
Expand All @@ -1519,9 +1523,6 @@ PHP_FUNCTION(sodium_crypto_pwhash)
zend_throw_exception(sodium_exception_ce, "unsupported password hashing algorithm", 0);
RETURN_THROWS();
}
if (passwd_len <= 0) {
zend_error(E_WARNING, "empty password");
}
if (salt_len != crypto_pwhash_SALTBYTES) {
zend_argument_error(sodium_exception_ce, 3, "must be SODIUM_CRYPTO_PWHASH_SALTBYTES bytes long");
RETURN_THROWS();
Expand Down Expand Up @@ -1574,6 +1575,14 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
sodium_remove_param_values_from_backtrace(EG(exception));
RETURN_THROWS();
}
if (passwd_len == 0) {
zend_argument_error(sodium_exception_ce, 1, "cannot be empty");
RETURN_THROWS();
}
if (passwd_len >= 0xffffffff) {
zend_argument_error(sodium_exception_ce, 1, "is too long");
RETURN_THROWS();
}
if (opslimit <= 0) {
zend_argument_error(sodium_exception_ce, 2, "must be greater than 0");
RETURN_THROWS();
Expand All @@ -1582,13 +1591,6 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
zend_argument_error(sodium_exception_ce, 3, "must be greater than 0");
RETURN_THROWS();
}
if (passwd_len >= 0xffffffff) {
zend_argument_error(sodium_exception_ce, 1, "is too long");
RETURN_THROWS();
}
if (passwd_len <= 0) {
zend_error(E_WARNING, "empty password");
}
if (opslimit < crypto_pwhash_OPSLIMIT_MIN) {
zend_argument_error(sodium_exception_ce, 2, "must be greater than or equal to %d", crypto_pwhash_OPSLIMIT_MIN);
}
Expand Down Expand Up @@ -1643,13 +1645,14 @@ PHP_FUNCTION(sodium_crypto_pwhash_str_verify)
sodium_remove_param_values_from_backtrace(EG(exception));
RETURN_THROWS();
}
if (passwd_len == 0) {
zend_argument_error(sodium_exception_ce, 2, "cannot be empty");
RETURN_THROWS();
}
if (passwd_len >= 0xffffffff) {
zend_argument_error(sodium_exception_ce, 2, "is too long");
RETURN_THROWS();
}
if (passwd_len <= 0) {
zend_error(E_WARNING, "empty password");
}
if (crypto_pwhash_str_verify
(hash_str, passwd, (unsigned long long) passwd_len) == 0) {
RETURN_TRUE;
Expand Down Expand Up @@ -1682,6 +1685,10 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
zend_argument_error(sodium_exception_ce, 1, "must be greater than 0");
RETURN_THROWS();
}
if (passwd_len == 0) {
zend_argument_error(sodium_exception_ce, 2, "cannot be empty");
RETURN_THROWS();
}
if (opslimit <= 0) {
zend_argument_error(sodium_exception_ce, 4, "must be greater than 0");
RETURN_THROWS();
Expand All @@ -1690,9 +1697,6 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
zend_argument_error(sodium_exception_ce, 5, "must be greater than 0");
RETURN_THROWS();
}
if (passwd_len <= 0) {
zend_error(E_WARNING, "empty password");
}
if (salt_len != crypto_pwhash_scryptsalsa208sha256_SALTBYTES) {
zend_argument_error(sodium_exception_ce, 3, "must be SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES bytes long");
RETURN_THROWS();
Expand Down Expand Up @@ -1731,6 +1735,10 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
sodium_remove_param_values_from_backtrace(EG(exception));
RETURN_THROWS();
}
if (passwd_len == 0) {
zend_argument_error(sodium_exception_ce, 1, "cannot be empty");
RETURN_THROWS();
}
if (opslimit <= 0) {
zend_argument_error(sodium_exception_ce, 2, "must be greater than 0");
RETURN_THROWS();
Expand All @@ -1739,9 +1747,6 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
zend_argument_error(sodium_exception_ce, 3, "must be greater than 0");
RETURN_THROWS();
}
if (passwd_len <= 0) {
zend_error(E_WARNING, "empty password");
}
if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) {
zend_argument_error(sodium_exception_ce, 2, "must be greater than or equal to %d", crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE);
}
Expand Down Expand Up @@ -1775,10 +1780,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify)
sodium_remove_param_values_from_backtrace(EG(exception));
RETURN_THROWS();
}
if (passwd_len <= 0) {
zend_error(E_WARNING, "empty password");
if (passwd_len == 0) {
zend_argument_error(sodium_exception_ce, 2, "cannot be empty");
RETURN_THROWS();
}
if (hash_str_len != crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1) {
/* Promote to Exception? */
zend_error(E_WARNING, "wrong size for the hashed password");
RETURN_FALSE;
}
Expand Down