Skip to content
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

add more checks for keylen #23

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function pbkdf2 (password, salt, iterations, keylen, digest, callback) {
})
}

function checkParameters(iterations, keylen) {
function checkParameters (iterations, keylen) {
if (typeof iterations !== 'number') {
throw new TypeError('Iterations not a number')
}
Expand All @@ -34,7 +34,7 @@ function checkParameters(iterations, keylen) {
throw new TypeError('Key length not a number')
}

if (keylen < 0 || keylen > MAX_ALLOC) {
if (keylen < 0 || keylen > MAX_ALLOC || isNaN(keylen)) {
throw new TypeError('Bad key length')
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function asyncPBKDF2 (password, salt, iterations, keylen, digest, callback) {
throw new TypeError('Key length not a number')
}

if (keylen < 0 || keylen > MAX_ALLOC) {
if (keylen < 0 || keylen > MAX_ALLOC || isNaN(keylen)) {
throw new TypeError('Bad key length')
}

Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ var compatNode = require('../')
var compatBrowser = require('../browser')
var fixtures = require('./fixtures')

fixtures.invalid.push({
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": NaN,
"exception": "Bad key length"
}, {
"key": "password",
"salt": "salt",
"iterations": 1,
"dkLen": Infinity,
"exception": "Bad key length"
})

// SHA-1 vectors generated by Node.js
// SHA-256/SHA-512 test vectors from:
// https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors
Expand Down