[Messaging] Fix for crash for 'from', 'cc' and 'bcc'. Fix for error handling.
authorPiotr Kosko <p.kosko@samsung.com>
Mon, 1 Jun 2015 09:54:07 +0000 (11:54 +0200)
committerHyunjin Park <hj.na.park@samsung.com>
Wed, 3 Jun 2015 04:40:07 +0000 (13:40 +0900)
[Bug] Application crash when mentioned members of sending message hold incorrect values.

[Verificaion] Code compiles without errors.
  SMS TCTs 100% passrate. Sample application Chatter does not crash anymore.

Change-Id: I930087ac37d573871df0d0ef1fca6689f3d0b9cd
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/messaging/messaging_api.js
src/messaging/messaging_util.cc

index 990aaf388867cc9576766a7895ab948113a1c465..46f11095cf886ee0ffeef2bd567ff1e87182145d 100755 (executable)
@@ -699,7 +699,7 @@ Messaging.prototype.getMessageServices = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -755,7 +755,7 @@ MessageService.prototype.sendMessage = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -799,7 +799,7 @@ MessageService.prototype.loadMessageBody = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -848,7 +848,7 @@ MessageService.prototype.loadMessageAttachment = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -875,7 +875,7 @@ MessageService.prototype.sync = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -914,7 +914,7 @@ MessageService.prototype.syncFolder = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -1003,7 +1003,7 @@ MessageStorage.prototype.addDraftMessage = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -1051,7 +1051,7 @@ MessageStorage.prototype.findMessages = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -1092,7 +1092,7 @@ MessageStorage.prototype.removeMessages = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -1155,7 +1155,7 @@ MessageStorage.prototype.updateMessages = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -1202,7 +1202,7 @@ MessageStorage.prototype.findConversations = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -1243,7 +1243,7 @@ MessageStorage.prototype.removeConversations = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
@@ -1286,7 +1286,7 @@ MessageStorage.prototype.findFolders = function () {
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
-                    new WebAPIException(e.code, e.message, e.name)
+                    new WebAPIException(e.error)
                 )
             }
         }
index c17ea7b2010109c21b354fb91dc4d243ff79e728..9d993dd0be41ac4da29a84ce4bb6422e801aed09 100755 (executable)
@@ -574,8 +574,18 @@ PlatformResult MessagingUtil::jsonToMessage(const picojson::value& json,
     }
 
     std::vector<std::string> result;
-    auto arrayVectorStringConverter = [&result] (picojson::value& v)->void {
-        result.push_back(v.get<std::string>());
+    PlatformResult conv_res(ErrorCode::NO_ERROR);
+    auto arrayVectorStringConverter = [&result, &conv_res] (picojson::value& v)->void {
+      if (!v.is<std::string>()) {
+        const std::string message = "Passed array holds incorrect values "
+            + v.serialize() + " is not a correct string value";
+        LoggerE("Error: %s", message.c_str());
+        conv_res = PlatformResult(ErrorCode::INVALID_VALUES_ERR, message);
+      }
+      if (conv_res.IsError()) {
+        return;
+      }
+      result.push_back(v.get<std::string>());
     };
 
     auto subject = MessagingUtil::getValueFromJSONObject<std::string>(data,
@@ -585,6 +595,9 @@ PlatformResult MessagingUtil::jsonToMessage(const picojson::value& json,
     auto toJS = MessagingUtil::getValueFromJSONObject<std::vector<picojson::value>>(data,
             MESSAGE_ATTRIBUTE_TO);
     for_each(toJS.begin(), toJS.end(), arrayVectorStringConverter);
+    if (conv_res.IsError()) {
+      return conv_res;
+    }
     message->setTO(result);
     result.clear();
 
@@ -592,12 +605,18 @@ PlatformResult MessagingUtil::jsonToMessage(const picojson::value& json,
     auto ccJS = MessagingUtil::getValueFromJSONObject<
             std::vector<picojson::value>>(data, MESSAGE_ATTRIBUTE_CC);
     for_each(ccJS.begin(), ccJS.end(), arrayVectorStringConverter);
+    if (conv_res.IsError()) {
+      return conv_res;
+    }
     message->setCC(result);
     result.clear();
 
     auto bccJS = MessagingUtil::getValueFromJSONObject<
             std::vector<picojson::value>>(data, MESSAGE_ATTRIBUTE_BCC);
     for_each(bccJS.begin(), bccJS.end(), arrayVectorStringConverter);
+    if (conv_res.IsError()) {
+      return conv_res;
+    }
     message->setBCC(result);
     result.clear();