Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1570)

Unified Diff: content/child/webcrypto/nss/hmac_nss.cc

Issue 508793002: Check for integer overflow when HMAC key length as bits cannot fit in an unsigned int. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/child/webcrypto/openssl/hmac_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/nss/hmac_nss.cc
diff --git a/content/child/webcrypto/nss/hmac_nss.cc b/content/child/webcrypto/nss/hmac_nss.cc
index f02be408d7f8064b09bafd3b843e9ea02226245d..40dadbe8a399e6dcbdbc4d5ec20dcd7b68e08aad 100644
--- a/content/child/webcrypto/nss/hmac_nss.cc
+++ b/content/child/webcrypto/nss/hmac_nss.cc
@@ -8,6 +8,7 @@
#include <sechash.h>
#include "base/logging.h"
+#include "base/numerics/safe_math.h"
#include "base/stl_util.h"
#include "content/child/webcrypto/algorithm_implementation.h"
#include "content/child/webcrypto/crypto_data.h"
@@ -109,16 +110,20 @@ class HmacImplementation : public AlgorithmImplementation {
if (!WebCryptoHashToHMACMechanism(hash, &mechanism))
return Status::ErrorUnsupported();
- // TODO(eroman): check for overflow.
- unsigned int keylen_bits = key_data.byte_length() * 8;
- return ImportKeyRawNss(
- key_data,
- blink::WebCryptoKeyAlgorithm::createHmac(hash.id(), keylen_bits),
- extractable,
- usage_mask,
- mechanism,
- CKF_SIGN | CKF_VERIFY,
- key);
+ base::CheckedNumeric<unsigned int> keylen_bits(key_data.byte_length());
+ keylen_bits *= 8;
+
+ if (!keylen_bits.IsValid())
+ return Status::ErrorDataTooLarge();
+
+ return ImportKeyRawNss(key_data,
+ blink::WebCryptoKeyAlgorithm::createHmac(
+ hash.id(), keylen_bits.ValueOrDie()),
+ extractable,
+ usage_mask,
+ mechanism,
+ CKF_SIGN | CKF_VERIFY,
+ key);
}
virtual Status ImportKeyJwk(const CryptoData& key_data,
« no previous file with comments | « no previous file | content/child/webcrypto/openssl/hmac_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698