]> granicus.if.org Git - php/commitdiff
Revert "remove excessive checks and fix warnings"
authorAnatol Belski <ab@php.net>
Tue, 11 Jul 2017 21:13:22 +0000 (23:13 +0200)
committerAnatol Belski <ab@php.net>
Tue, 11 Jul 2017 21:13:22 +0000 (23:13 +0200)
This reverts commit c620daecb4f8b1552eb3f63f6a699ea315825072.

ext/sodium/libsodium.c

index b20ffc79a1536a1ac5bb8294027165b8e640df24..10c23310bd63f9cea259f81455ce6d6041b6fcca 100644 (file)
@@ -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;
        }