[Contact] Added more restrictive validation of filter in findByUsageCount 49/71849/1
authorPiotr Kosko <p.kosko@samsung.com>
Fri, 27 May 2016 10:05:50 +0000 (12:05 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 27 May 2016 10:05:53 +0000 (12:05 +0200)
[Feature] Added more validation of filter in findByUsageCount - value and type are checked
  for validyty - value shouldn't be less than 0, type should be one of values in enum.

[Verification] Code compiles without errors.
  Contact TCT passrate r11 is 100%.

Change-Id: Iee3b6a86eb931f6fda3fc9304771837d5a4f5ad5
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/contact/contact_manager.cc

index 319811fbdbc09281b273785993b6980149a399ff..aeab4f2d0ea606d9e841915531135b4004195da1 100755 (executable)
@@ -925,6 +925,10 @@ PlatformResult ContactManagerFindByUsageCount(const JsonObject& args, JsonArray&
     const auto& match = filter.get("matchValue");
     if (match.is<double>()){
       match_value = static_cast<int>(match.get<double>());
+      if (match_value < 0) {
+        return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+                              "Match value cannot be less than 0");
+      }
       ret = contacts_filter_add_int(filter_handle,
                                     _contacts_person_usage.times_used,
                                     CONTACTS_MATCH_EQUAL,
@@ -989,6 +993,10 @@ PlatformResult ContactManagerFindByUsageCount(const JsonObject& args, JsonArray&
   }
   // adding usage type to filter
   contacts_usage_type_e type = Person::UsageTypeFromString(attribute_name);
+  if (CONTACTS_USAGE_STAT_TYPE_NONE == type) {
+    return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR,
+                              "Type of usage in filter should be one of ContactUsageType values");
+  }
   ret = contacts_filter_add_int(filter_handle,
                                 _contacts_person_usage.usage_type,
                                 CONTACTS_MATCH_EQUAL,