| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 610bd8d commit da3f425
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ | |||
| 19 | 19 | #include "CNNICHashWhitelist.inc" | |
| 20 | 20 | ||
| 21 | 21 | #include <errno.h> | |
| 22 | + #include <limits.h> // INT_MAX | ||
| 22 | 23 | #include <math.h> | |
| 23 | 24 | #include <stdlib.h> | |
| 24 | 25 | #include <string.h> | |
@@ -4955,12 +4956,12 @@ class PBKDF2Request : public AsyncWrap { | |||
| 4955 | 4956 | PBKDF2Request(Environment* env, | |
| 4956 | 4957 | Local<Object> object, | |
| 4957 | 4958 | const EVP_MD* digest, | |
| 4958 | - ssize_t passlen, | ||
| 4959 | + int passlen, | ||
| 4959 | 4960 | char* pass, | |
| 4960 | - ssize_t saltlen, | ||
| 4961 | + int saltlen, | ||
| 4961 | 4962 | char* salt, | |
| 4962 | - ssize_t iter, | ||
| 4963 | - ssize_t keylen) | ||
| 4963 | + int iter, | ||
| 4964 | + int keylen) | ||
| 4964 | 4965 | : AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO), | |
| 4965 | 4966 | digest_(digest), | |
| 4966 | 4967 | error_(0), | |
@@ -4989,31 +4990,31 @@ class PBKDF2Request : public AsyncWrap { | |||
| 4989 | 4990 | return digest_; | |
| 4990 | 4991 | } | |
| 4991 | 4992 | ||
| 4992 | - inline ssize_t passlen() const { | ||
| 4993 | + inline int passlen() const { | ||
| 4993 | 4994 | return passlen_; | |
| 4994 | 4995 | } | |
| 4995 | 4996 | ||
| 4996 | 4997 | inline char* pass() const { | |
| 4997 | 4998 | return pass_; | |
| 4998 | 4999 | } | |
| 4999 | 5000 | ||
| 5000 | - inline ssize_t saltlen() const { | ||
| 5001 | + inline int saltlen() const { | ||
| 5001 | 5002 | return saltlen_; | |
| 5002 | 5003 | } | |
| 5003 | 5004 | ||
| 5004 | 5005 | inline char* salt() const { | |
| 5005 | 5006 | return salt_; | |
| 5006 | 5007 | } | |
| 5007 | 5008 | ||
| 5008 | - inline ssize_t keylen() const { | ||
| 5009 | + inline int keylen() const { | ||
| 5009 | 5010 | return keylen_; | |
| 5010 | 5011 | } | |
| 5011 | 5012 | ||
| 5012 | 5013 | inline char* key() const { | |
| 5013 | 5014 | return key_; | |
| 5014 | 5015 | } | |
| 5015 | 5016 | ||
| 5016 | - inline ssize_t iter() const { | ||
| 5017 | + inline int iter() const { | ||
| 5017 | 5018 | return iter_; | |
| 5018 | 5019 | } | |
| 5019 | 5020 | ||
@@ -5046,13 +5047,13 @@ class PBKDF2Request : public AsyncWrap { | |||
| 5046 | 5047 | private: | |
| 5047 | 5048 | const EVP_MD* digest_; | |
| 5048 | 5049 | int error_; | |
| 5049 | - ssize_t passlen_; | ||
| 5050 | + int passlen_; | ||
| 5050 | 5051 | char* pass_; | |
| 5051 | - ssize_t saltlen_; | ||
| 5052 | + int saltlen_; | ||
| 5052 | 5053 | char* salt_; | |
| 5053 | - ssize_t keylen_; | ||
| 5054 | + int keylen_; | ||
| 5054 | 5055 | char* key_; | |
| 5055 | - ssize_t iter_; | ||
| 5056 | + int iter_; | ||
| 5056 | 5057 | }; | |
| 5057 | 5058 | ||
| 5058 | 5059 | ||
@@ -5109,10 +5110,11 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { | |||
| 5109 | 5110 | const char* type_error = nullptr; | |
| 5110 | 5111 | char* pass = nullptr; | |
| 5111 | 5112 | char* salt = nullptr; | |
| 5112 | - ssize_t passlen = -1; | ||
| 5113 | - ssize_t saltlen = -1; | ||
| 5114 | - double keylen = -1; | ||
| 5115 | - ssize_t iter = -1; | ||
| 5113 | + int passlen = -1; | ||
| 5114 | + int saltlen = -1; | ||
| 5115 | + double raw_keylen = -1; | ||
| 5116 | + int keylen = -1; | ||
| 5117 | + int iter = -1; | ||
| 5116 | 5118 | PBKDF2Request* req = nullptr; | |
| 5117 | 5119 | Local<Object> obj; | |
| 5118 | 5120 | ||
@@ -5164,12 +5166,15 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { | |||
| 5164 | 5166 | goto err; | |
| 5165 | 5167 | } | |
| 5166 | 5168 | ||
| 5167 | - keylen = args[3]->NumberValue(); | ||
| 5168 | - if (keylen < 0 || isnan(keylen) || isinf(keylen)) { | ||
| 5169 | + raw_keylen = args[3]->NumberValue(); | ||
| 5170 | + if (raw_keylen < 0.0 || isnan(raw_keylen) || isinf(raw_keylen) || | ||
| 5171 | + raw_keylen > INT_MAX) { | ||
| 5169 | 5172 | type_error = "Bad key length"; | |
| 5170 | 5173 | goto err; | |
| 5171 | 5174 | } | |
| 5172 | 5175 | ||
| 5176 | + keylen = static_cast<int>(raw_keylen); | ||
| 5177 | + | ||
| 5173 | 5178 | if (args[4]->IsString()) { | |
| 5174 | 5179 | node::Utf8Value digest_name(env->isolate(), args[4]); | |
| 5175 | 5180 | digest = EVP_get_digestbyname(*digest_name); | |
@@ -5192,7 +5197,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { | |||
| 5192 | 5197 | saltlen, | |
| 5193 | 5198 | salt, | |
| 5194 | 5199 | iter, | |
| 5195 | - static_cast<ssize_t>(keylen)); | ||
| 5200 | + keylen); | ||
| 5196 | 5201 | ||
| 5197 | 5202 | if (args[5]->IsFunction()) { | |
| 5198 | 5203 | obj->Set(env->ondone_string(), args[5]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,27 +63,24 @@ assert.throws(function() { | |||
| 63 | 63 | // Should not work with Infinity key length | |
| 64 | 64 | assert.throws(function() { | |
| 65 | 65 | crypto.pbkdf2('password', 'salt', 1, Infinity, 'sha256', common.fail); | |
| 66 | - }, function(err) { | ||
| 67 | - return err instanceof Error && err.message === 'Bad key length'; | ||
| 68 | - }); | ||
| 66 | + }, /Bad key length/); | ||
| 69 | 67 | ||
| 70 | 68 | // Should not work with negative Infinity key length | |
| 71 | 69 | assert.throws(function() { | |
| 72 | 70 | crypto.pbkdf2('password', 'salt', 1, -Infinity, 'sha256', common.fail); | |
| 73 | - }, function(err) { | ||
| 74 | - return err instanceof Error && err.message === 'Bad key length'; | ||
| 75 | - }); | ||
| 71 | + }, /Bad key length/); | ||
| 76 | 72 | ||
| 77 | 73 | // Should not work with NaN key length | |
| 78 | 74 | assert.throws(function() { | |
| 79 | 75 | crypto.pbkdf2('password', 'salt', 1, NaN, 'sha256', common.fail); | |
| 80 | - }, function(err) { | ||
| 81 | - return err instanceof Error && err.message === 'Bad key length'; | ||
| 82 | - }); | ||
| 76 | + }, /Bad key length/); | ||
| 83 | 77 | ||
| 84 | 78 | // Should not work with negative key length | |
| 85 | 79 | assert.throws(function() { | |
| 86 | 80 | crypto.pbkdf2('password', 'salt', 1, -1, 'sha256', common.fail); | |
| 87 | - }, function(err) { | ||
| 88 | - return err instanceof Error && err.message === 'Bad key length'; | ||
| 89 | - }); | ||
| 81 | + }, /Bad key length/); | ||
| 82 | + | ||
| 83 | + // Should not work with key length that does not fit into 32 signed bits | ||
| 84 | + assert.throws(function() { | ||
| 85 | + crypto.pbkdf2('password', 'salt', 1, 4073741824, 'sha256', common.fail); | ||
| 86 | + }, /Bad key length/); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments