From d1ee66655b9df3ad7f8cfc08790964b6b90558e5 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 11 Jul 2017 23:13:22 +0200 Subject: [PATCH] Revert "remove excessive checks and fix warnings" This reverts commit c620daecb4f8b1552eb3f63f6a699ea315825072. --- ext/sodium/libsodium.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index b20ffc79a1..10c23310bd 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -1636,7 +1636,8 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256) &passwd, &passwd_len, &salt, &salt_len, &opslimit, &memlimit) == FAILURE || - hash_len <= 0 || opslimit <= 0 || memlimit <= 0) { + hash_len <= 0 || hash_len >= SIZE_MAX || + opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "crypto_pwhash_scryptsalsa208sha256(): invalid parameters", 0); return; } @@ -1649,11 +1650,11 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256) 0); return; } - if ((size_t)opslimit < crypto_pwhash_scryptsalsa208sha256_opslimit_interactive()) { + if (opslimit < crypto_pwhash_scryptsalsa208sha256_opslimit_interactive()) { zend_error(E_WARNING, "number of operations for the scrypt function is low"); } - if ((size_t)memlimit < crypto_pwhash_scryptsalsa208sha256_memlimit_interactive()) { + if (memlimit < crypto_pwhash_scryptsalsa208sha256_memlimit_interactive()) { zend_error(E_WARNING, "maximum memory for the scrypt function is low"); } @@ -1682,7 +1683,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str) if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll", &passwd, &passwd_len, &opslimit, &memlimit) == FAILURE || - opslimit <= 0 || memlimit <= 0) { + opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "crypto_pwhash_scryptsalsa208sha256_str(): invalid parameters", 0); @@ -1691,11 +1692,11 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str) if (passwd_len <= 0) { zend_error(E_WARNING, "empty password"); } - if ((size_t)opslimit < crypto_pwhash_scryptsalsa208sha256_opslimit_interactive()) { + if (opslimit < crypto_pwhash_scryptsalsa208sha256_opslimit_interactive()) { zend_error(E_WARNING, "number of operations for the scrypt function is low"); } - if ((size_t)memlimit < crypto_pwhash_scryptsalsa208sha256_memlimit_interactive()) { + if (memlimit < crypto_pwhash_scryptsalsa208sha256_memlimit_interactive()) { zend_error(E_WARNING, "maximum memory for the scrypt function is low"); } @@ -1759,7 +1760,8 @@ PHP_FUNCTION(sodium_crypto_pwhash) &passwd, &passwd_len, &salt, &salt_len, &opslimit, &memlimit) == FAILURE || - hash_len <= 0 || opslimit <= 0 || memlimit <= 0) { + hash_len <= 0 || hash_len >= SIZE_MAX || + opslimit <= 0 || memlimit <= 0 || memlimit > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "crypto_pwhash(): invalid parameters", 0); return; } -- 2.40.0