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

crypto: PBKDF2 works with int not ssize_t #5397

Closed
wants to merge 4 commits into from

Conversation

indutny
Copy link
Member

@indutny indutny commented Feb 23, 2016

Pull Request check-list

Please make sure to review and check all of these items:

  • Does make -j8 test (UNIX) or vcbuild test nosign (Windows) pass with
    this change (including linting)?
  • Is the commit message formatted according to CONTRIBUTING.md?
  • If this change fixes a bug (or a performance problem), is a regression
    test (or a benchmark) included?
  • Is a documentation update included (if this change modifies
    existing APIs, or introduces new ones)?

NOTE: these things are not required to open a PR and can be done afterwards /
while the PR is open.

Affected core subsystem(s)

Please provide affected core subsystem(s) (like buffer, cluster, crypto, etc)

Description of change

Change types of all PBKDF2 params to int as they are int in evp.h.

Check that raw_keylen fits into int before passing it to OpenSSL.

Fix: #5396

Change types of all PBKDF2 params to `int` as they are `int` in `evp.h`.

Check that `raw_keylen` fits into `int` before passing it to OpenSSL.

Fix: nodejs#5396
@indutny
Copy link
Member Author

indutny commented Feb 23, 2016

cc @nodejs/crypto

R = @bnoordhuis or @shigeki

@mscdex mscdex added crypto Issues and PRs related to the crypto subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. labels Feb 23, 2016
@dcousens
Copy link

ACK.

@shigeki
Copy link
Contributor

shigeki commented Feb 24, 2016

LGTM if CI is fine.

@indutny
Copy link
Member Author

indutny commented Feb 24, 2016

@shigeki I'm afraid that CI is down 😢

(please pardon my terrible sense of humor).

@shigeki
Copy link
Contributor

shigeki commented Feb 24, 2016

@indutny lol :-) Hoping it's back soon from #5194.

crypto.pbkdf2('password', 'salt', 1, 4073741824, 'sha256', common.fail);
}, function(err) {
return err instanceof Error && err.message === 'Bad key length';
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can condense the check callback to just /Bad key length/.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@bnoordhuis
Copy link
Member

LGTM with a suggestion.

@indutny
Copy link
Member Author

indutny commented Feb 25, 2016

@indutny
Copy link
Member Author

indutny commented Feb 26, 2016

@bnoordhuis I took some courage and changed the rest of "Bad key length" occurrences. Hopefully this is OK to you.

@indutny
Copy link
Member Author

indutny commented Feb 26, 2016

CI is unhappy with the change. Looks like I will need to study this a bit more than I thought.

keylen = args[3]->NumberValue();
if (keylen < 0 || isnan(keylen) || isinf(keylen)) {
raw_keylen = args[3]->NumberValue();
if (raw_keylen < 0.0 || isnan(raw_keylen) || isinf(raw_keylen)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably write this as:

if (!std::isfinite(raw_keylen) || raw_keylen < 0 || raw_keylen > INT_MAX) {
  // ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@indutny
Copy link
Member Author

indutny commented Mar 1, 2016

@indutny
Copy link
Member Author

indutny commented Mar 1, 2016

CI is green, the commit goes in. Landed in da3f425, thank you everyone!

@indutny indutny closed this Mar 1, 2016
indutny added a commit that referenced this pull request Mar 1, 2016
Change types of all PBKDF2 params to `int` as they are `int` in `evp.h`.

Check that `raw_keylen` fits into `int` before passing it to OpenSSL.

Fix: #5396
PR-URL: #5397
Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
Reviewed-By: Ben Noorhduis <info@bnoordhuis.nl>
@indutny indutny deleted the fix/gh-5396 branch March 1, 2016 06:08
@Fishrock123 Fishrock123 mentioned this pull request Mar 1, 2016
5 tasks
Fishrock123 pushed a commit that referenced this pull request Mar 2, 2016
Change types of all PBKDF2 params to `int` as they are `int` in `evp.h`.

Check that `raw_keylen` fits into `int` before passing it to OpenSSL.

Fix: #5396
PR-URL: #5397
Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
Reviewed-By: Ben Noorhduis <info@bnoordhuis.nl>

Conflicts:
	test/parallel/test-crypto-pbkdf2.js
MylesBorins pushed a commit that referenced this pull request Mar 17, 2016
Change types of all PBKDF2 params to `int` as they are `int` in `evp.h`.

Check that `raw_keylen` fits into `int` before passing it to OpenSSL.

Fix: #5396
PR-URL: #5397
Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
Reviewed-By: Ben Noorhduis <info@bnoordhuis.nl>
MylesBorins pushed a commit that referenced this pull request Mar 21, 2016
Change types of all PBKDF2 params to `int` as they are `int` in `evp.h`.

Check that `raw_keylen` fits into `int` before passing it to OpenSSL.

Fix: #5396
PR-URL: #5397
Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
Reviewed-By: Ben Noorhduis <info@bnoordhuis.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crypto.pbkdf2 with an keylen too long crashes in a segfalt
7 participants