From: Piotr Kosko Date: Mon, 1 Jun 2015 09:54:07 +0000 (+0200) Subject: [Messaging] Fix for crash for 'from', 'cc' and 'bcc'. Fix for error handling. X-Git-Tag: submit/tizen_tv/20150603.064601^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0026cc961272339003a2215c45ea578f146c9c19;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Messaging] Fix for crash for 'from', 'cc' and 'bcc'. Fix for error handling. [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 --- diff --git a/src/messaging/messaging_api.js b/src/messaging/messaging_api.js index 990aaf38..46f11095 100755 --- a/src/messaging/messaging_api.js +++ b/src/messaging/messaging_api.js @@ -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) ) } } diff --git a/src/messaging/messaging_util.cc b/src/messaging/messaging_util.cc index c17ea7b2..9d993dd0 100755 --- a/src/messaging/messaging_util.cc +++ b/src/messaging/messaging_util.cc @@ -574,8 +574,18 @@ PlatformResult MessagingUtil::jsonToMessage(const picojson::value& json, } std::vector result; - auto arrayVectorStringConverter = [&result] (picojson::value& v)->void { - result.push_back(v.get()); + PlatformResult conv_res(ErrorCode::NO_ERROR); + auto arrayVectorStringConverter = [&result, &conv_res] (picojson::value& v)->void { + if (!v.is()) { + 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()); }; auto subject = MessagingUtil::getValueFromJSONObject(data, @@ -585,6 +595,9 @@ PlatformResult MessagingUtil::jsonToMessage(const picojson::value& json, auto toJS = MessagingUtil::getValueFromJSONObject>(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>(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>(data, MESSAGE_ATTRIBUTE_BCC); for_each(bccJS.begin(), bccJS.end(), arrayVectorStringConverter); + if (conv_res.IsError()) { + return conv_res; + } message->setBCC(result); result.clear();