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: fix UB in computing max message size #21462

Closed
wants to merge 0 commits into from

Conversation

bnoordhuis
Copy link
Member

Before this commit it computed (1<<(8*(15-iv_len)))-1 for iv_len>=11
and that reduces to (1<<32)-1 for iv_len==11. Left-shifting past
the sign bit and overflowing a signed integral type are both undefined
behaviors.

This commit switches to fixed values and restricts the iv_len==11
case to INT_MAX, as was already the case for all iv_len<=10.

@bnoordhuis bnoordhuis requested a review from tniessen June 22, 2018 11:11
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. labels Jun 22, 2018
@bnoordhuis bnoordhuis closed this Jun 25, 2018
@bnoordhuis bnoordhuis force-pushed the fix-crypto-auth-iv-ub branch from 6bdf825 to 19fe529 Compare June 25, 2018 21:46
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Jun 25, 2018
Before this commit it computed `(1<<(8*(15-iv_len)))-1` for `iv_len>=11`
and that reduces to `(1<<32)-1` for `iv_len==11`.  Left-shifting past
the sign bit and overflowing a signed integral type are both undefined
behaviors.

This commit switches to fixed values and restricts the `iv_len==11`
case to `INT_MAX`, as was already the case for all `iv_len<=10`.

PR-URL: nodejs#21462
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@bnoordhuis bnoordhuis deleted the fix-crypto-auth-iv-ub branch June 25, 2018 21:46
@bnoordhuis
Copy link
Member Author

Landed in 19fe529.

targos pushed a commit that referenced this pull request Jun 26, 2018
Before this commit it computed `(1<<(8*(15-iv_len)))-1` for `iv_len>=11`
and that reduces to `(1<<32)-1` for `iv_len==11`.  Left-shifting past
the sign bit and overflowing a signed integral type are both undefined
behaviors.

This commit switches to fixed values and restricts the `iv_len==11`
case to `INT_MAX`, as was already the case for all `iv_len<=10`.

PR-URL: #21462
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@targos targos mentioned this pull request Jul 3, 2018
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.

5 participants