summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/policy/core/common/schema.cc20
-rw-r--r--components/policy/core/common/schema_internal.h16
2 files changed, 21 insertions, 15 deletions
diff --git a/components/policy/core/common/schema.cc b/components/policy/core/common/schema.cc
index c15e9b5514..2cf6930d17 100644
--- a/components/policy/core/common/schema.cc
+++ b/components/policy/core/common/schema.cc
@@ -39,12 +39,12 @@ namespace {
struct ReferencesAndIDs {
// Maps schema "id" attributes to the corresponding SchemaNode index.
- std::map<std::string, int> id_map;
+ std::map<std::string, short> id_map;
// List of pairs of references to be assigned later. The string is the "id"
// whose corresponding index should be stored in the pointer, once all the IDs
// are available.
- std::vector<std::pair<std::string, int*>> reference_list;
+ std::vector<std::pair<std::string, short*>> reference_list;
};
// Sizes for the storage arrays. These are calculated in advance so that the
@@ -78,7 +78,7 @@ constexpr char kSensitiveValueMask[] = "********";
// An invalid index, indicating that a node is not present; similar to a NULL
// pointer.
-const int kInvalid = -1;
+const short kInvalid = -1;
// Maps a schema key to the corresponding base::Value::Type
struct SchemaKeyToValueType {
@@ -576,7 +576,7 @@ class Schema::InternalStorage
// If |schema| is invalid then |error| gets the error reason and false is
// returned. Otherwise returns true.
bool Parse(const base::DictionaryValue& schema,
- int* index,
+ short* index,
ReferencesAndIDs* references_and_ids,
std::string* error);
@@ -681,7 +681,7 @@ Schema::InternalStorage::ParseSchema(const base::DictionaryValue& schema,
storage->int_enums_.reserve(sizes.int_enums);
storage->string_enums_.reserve(sizes.string_enums);
- int root_index = kInvalid;
+ short root_index = kInvalid;
ReferencesAndIDs references_and_ids;
if (!storage->Parse(schema, &root_index, &references_and_ids, error))
return nullptr;
@@ -822,7 +822,7 @@ void Schema::InternalStorage::DetermineStorageSizes(
}
bool Schema::InternalStorage::Parse(const base::DictionaryValue& schema,
- int* index,
+ short* index,
ReferencesAndIDs* references_and_ids,
std::string* error) {
std::string ref_string;
@@ -848,7 +848,13 @@ bool Schema::InternalStorage::Parse(const base::DictionaryValue& schema,
return false;
}
- *index = static_cast<int>(schema_nodes_.size());
+ if (schema_nodes_.size() > std::numeric_limits<short>::max()) {
+ *error = "Can't have more than " +
+ std::to_string(std::numeric_limits<short>::max()) +
+ " schema nodes.";
+ return false;
+ }
+ *index = static_cast<short>(schema_nodes_.size());
schema_nodes_.push_back(SchemaNode());
SchemaNode* schema_node = &schema_nodes_.back();
schema_node->type = type;
diff --git a/components/policy/core/common/schema_internal.h b/components/policy/core/common/schema_internal.h
index fe2937cca8..7213cf0c62 100644
--- a/components/policy/core/common/schema_internal.h
+++ b/components/policy/core/common/schema_internal.h
@@ -34,7 +34,7 @@ struct POLICY_EXPORT SchemaNode {
// RestrictionNode describing the restriction on the value.
//
// Otherwise extra is -1 and is invalid.
- int extra;
+ short extra;
// True if this value is sensitive and should be masked before displaying it
// to the user.
@@ -51,14 +51,14 @@ struct POLICY_EXPORT PropertyNode {
// An offset into SchemaData::schema_nodes that indexes the SchemaNode
// describing the structure of this key.
- int schema;
+ short schema;
};
// Represents the list of keys of a map policy.
struct POLICY_EXPORT PropertiesNode {
// An offset into SchemaData::property_nodes that indexes the PropertyNode
// describing the first known property of this map policy.
- int begin;
+ short begin;
// An offset into SchemaData::property_nodes that indexes the PropertyNode
// right beyond the last known property of this map policy.
@@ -68,18 +68,18 @@ struct POLICY_EXPORT PropertiesNode {
//
// Note that the range [begin, end) is sorted by PropertyNode::key, so that
// properties can be looked up by binary searching in the range.
- int end;
+ short end;
// An offset into SchemaData::property_nodes that indexes the PropertyNode
// right beyond the last known pattern property.
//
// [end, pattern_end) is the range that covers all pattern properties
// defined. It's not required to be sorted.
- int pattern_end;
+ short pattern_end;
// An offset into SchemaData::required_properties that indexes the first
// required property of this map policy.
- int required_begin;
+ short required_begin;
// An offset into SchemaData::required_properties that indexes the property
// right beyond the last required property.
@@ -88,14 +88,14 @@ struct POLICY_EXPORT PropertiesNode {
// PropertiesNode corresponds to does not have any required properties.
//
// Note that the range [required_begin, required_end) is not sorted.
- int required_end;
+ short required_end;
// If this map policy supports keys with any value (besides the well-known
// values described in the range [begin, end)) then |additional| is an offset
// into SchemaData::schema_nodes that indexes the SchemaNode describing the
// structure of the values for those keys. Otherwise |additional| is -1 and
// is invalid.
- int additional;
+ short additional;
};
// Represents the restriction on Type::INTEGER or Type::STRING instance of