Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 36ae3cc

Browse filesBrowse files
tniessenRafaelGSS
authored andcommitted
src: replace unreachable code with static_assert
This function base64-decodes a given JavaScript string to obtain the secret key, whose length must not exceed INT_MAX. However, because JavaScript strings are limited to v8::String::kMaxLength chars and because base64 decoding never yields more bytes than input chars, the size of the decoded key must be strictly less than v8::String::kMaxLength bytes. Therefore, it is sufficient to statically assert that String::kMaxLength <= INT_MAX (which is always true because String::kMaxLength itself is an int). Aside from being unreachable, Coverity considers the current code "suspicious" because it indicates that buffers larger than INT_MAX might actually be allocated. PR-URL: #46209 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ae5141c commit 36ae3cc
Copy full SHA for 36ae3cc

File tree

Expand file treeCollapse file tree

1 file changed

+1
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+1
-5
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_keys.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_keys.cc
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,8 @@ std::shared_ptr<KeyObjectData> ImportJWKSecretKey(
479479
return std::shared_ptr<KeyObjectData>();
480480
}
481481

482+
static_assert(String::kMaxLength <= INT_MAX);
482483
ByteSource key_data = ByteSource::FromEncodedString(env, key.As<String>());
483-
if (key_data.size() > INT_MAX) {
484-
THROW_ERR_CRYPTO_INVALID_KEYLEN(env);
485-
return std::shared_ptr<KeyObjectData>();
486-
}
487-
488484
return KeyObjectData::CreateSecret(std::move(key_data));
489485
}
490486

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.