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

Unified Diff: Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 23361019: WebCrypto: properly normalize optional numeric parameters. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Replace contains() with a different get() method Created 7 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 | « Source/bindings/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/NormalizeAlgorithm.cpp
diff --git a/Source/modules/crypto/NormalizeAlgorithm.cpp b/Source/modules/crypto/NormalizeAlgorithm.cpp
index 91925e71a6be08647747935958a39741c9d0150c..c53c7c66b99d8e9c4a4e05200467323e32ae0a26 100644
--- a/Source/modules/crypto/NormalizeAlgorithm.cpp
+++ b/Source/modules/crypto/NormalizeAlgorithm.cpp
@@ -235,23 +235,23 @@ bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
return true;
}
-bool getInteger(const Dictionary& raw, const char* propertyName, double& value, double minValue, double maxValue, const ExceptionContext& context, ExceptionState& es)
+// Gets an integer according to WebIDL's [EnforceRange].
+bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& hasProperty, double& value, double minValue, double maxValue, const ExceptionContext& context, ExceptionState& es)
{
double number;
- if (!raw.get(propertyName, number)) {
- es.throwTypeError(context.toString(propertyName, "Missing or not a number"));
- return false;
- }
+ bool ok = raw.get(propertyName, number, hasProperty);
- // Convert to an integer according to WebIDL's [EnforceRange].
- if (std::isinf(number) || std::isnan(number)) {
- es.throwTypeError(context.toString(propertyName, "Outside of numeric range"));
+ if (!hasProperty)
+ return true;
+
+ if (!ok || std::isnan(number)) {
+ es.throwTypeError(context.toString(propertyName, "Is not a number"));
return false;
}
number = trunc(number);
- if (number < minValue || number > maxValue) {
+ if (std::isinf(number) || number < minValue || number > maxValue) {
es.throwTypeError(context.toString(propertyName, "Outside of numeric range"));
return false;
}
@@ -260,17 +260,18 @@ bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
return true;
}
-bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& hasValue, double& value, double minValue, double maxValue, const ExceptionContext& context, ExceptionState& es)
+bool getInteger(const Dictionary& raw, const char* propertyName, double& value, double minValue, double maxValue, const ExceptionContext& context, ExceptionState& es)
{
- double number;
- if (!raw.get(propertyName, number)) {
- // FIXME: If the property exists but is NOT a number, should fail.
- hasValue = false;
- return true;
+ bool hasProperty;
+ if (!getOptionalInteger(raw, propertyName, hasProperty, value, minValue, maxValue, context, es))
+ return false;
+
+ if (!hasProperty) {
+ es.throwTypeError(context.toString(propertyName, "Missing required property"));
+ return false;
}
- hasValue = true;
- return getInteger(raw, propertyName, value, minValue, maxValue, context, es);
+ return true;
}
bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value, const ExceptionContext& context, ExceptionState& es)
@@ -357,7 +358,7 @@ bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithm
return false;
bool hasLength;
- uint32_t length;
+ uint32_t length = 0;
if (!getOptionalUint32(raw, "length", hasLength, length, context, es))
return false;
« no previous file with comments | « Source/bindings/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698