com php-src: Improve sodium "invalid parameters" error messages: ext/sodium/libsodium.c
| From: | Nikita Popov | Date: | Thu, 07 Sep 2017 20:18:48 +0000 |
| Subject: | com php-src: Improve sodium "invalid parameters" error messages: ext/sodium/libsodium.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99309@lists.php.net to get a copy of this message | ||
Commit: b786e1b45c065650910c7225db4c1b57bbf76834
Author: Sammy Kaye Powers <sammyk@sammykmedia.com> Tue, 5 Sep 2017 12:29:03 -0500
Committer: Nikita Popov <nikita.ppv@gmail.com> Thu, 7 Sep 2017 22:18:48 +0200
Parents: fd07302024bc47082b13b32217147fd39d1e9e61
Branches: PHP-7.2 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b786e1b45c065650910c7225db4c1b57bbf76834
Log:
Improve sodium "invalid parameters" error messages
Changed paths:
M ext/sodium/libsodium.c
Diff:
diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c
index 66eb1f4..2c48b44 100644
--- a/ext/sodium/libsodium.c
+++ b/ext/sodium/libsodium.c
@@ -1645,7 +1645,7 @@ PHP_FUNCTION(sodium_crypto_stream)
return;
}
if (ciphertext_len <= 0 || ciphertext_len >= SIZE_MAX) {
- zend_throw_exception(sodium_exception_ce, "invalid length", 0);
+ zend_throw_exception(sodium_exception_ce, "ciphertext length must be greater than 0",
0);
return;
}
if (nonce_len != crypto_stream_NONCEBYTES) {
@@ -1727,9 +1727,16 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
sodium_remove_param_values_from_backtrace(EG(exception));
return;
}
- if (hash_len <= 0 || hash_len >= SIZE_MAX || hash_len > 0x1fffffffe0ULL ||
- opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX) {
- zend_throw_exception(sodium_exception_ce, "invalid parameters", 0);
+ if (hash_len <= 0 || hash_len >= SIZE_MAX || hash_len > 0x1fffffffe0ULL) {
+ zend_throw_exception(sodium_exception_ce, "hash length must be greater than 0", 0);
+ return;
+ }
+ if (opslimit <= 0) {
+ zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0);
+ return;
+ }
+ if (memlimit <= 0 || memlimit > SIZE_MAX) {
+ zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0);
return;
}
if (passwd_len <= 0) {
@@ -1777,8 +1784,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
sodium_remove_param_values_from_backtrace(EG(exception));
return;
}
- if (opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX) {
- zend_throw_exception(sodium_exception_ce, "invalid parameters", 0);
+ if (opslimit <= 0) {
+ zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0);
+ return;
+ }
+ if (memlimit <= 0 || memlimit > SIZE_MAX) {
+ zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0);
return;
}
if (passwd_len <= 0) {
@@ -1856,10 +1867,20 @@ PHP_FUNCTION(sodium_crypto_pwhash)
sodium_remove_param_values_from_backtrace(EG(exception));
return;
}
- if (hash_len <= 0 || hash_len >= 0xffffffff ||
- passwd_len >= 0xffffffff ||
- opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX) {
- zend_throw_exception(sodium_exception_ce, "invalid parameters", 0);
+ if (hash_len <= 0 || hash_len >= 0xffffffff) {
+ zend_throw_exception(sodium_exception_ce, "hash length must be greater than 0", 0);
+ return;
+ }
+ if (passwd_len >= 0xffffffff) {
+ zend_throw_exception(sodium_exception_ce, "unsupported password length", 0);
+ return;
+ }
+ if (opslimit <= 0) {
+ zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0);
+ return;
+ }
+ if (memlimit <= 0 || memlimit > SIZE_MAX) {
+ zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0);
return;
}
if (alg != crypto_pwhash_ALG_ARGON2I13
@@ -1914,9 +1935,16 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
sodium_remove_param_values_from_backtrace(EG(exception));
return;
}
- if (opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX ||
- passwd_len >= 0xffffffff) {
- zend_throw_exception(sodium_exception_ce, "invalid parameters", 0);
+ if (opslimit <= 0) {
+ zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0);
+ return;
+ }
+ if (memlimit <= 0 || memlimit > SIZE_MAX) {
+ zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0);
+ return;
+ }
+ if (passwd_len >= 0xffffffff) {
+ zend_throw_exception(sodium_exception_ce, "unsupported password length", 0);
return;
}
if (passwd_len <= 0) {