From: Lukasz Stanislawski Date: Mon, 20 Mar 2017 15:43:55 +0000 (+0100) Subject: Time: fix string conversion routine X-Git-Tag: submit/tizen/20170320.161623~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cffa0179f946024e3b59563c204636c6120e4b0f;p=profile%2Fmobile%2Fapps%2Fnative%2Fclock.git Time: fix string conversion routine The previous routine may caused buffer overflows if unicode codepoints couldn't be encoded on single byte. The return value of i18n_ustring_get_length was incorrectly understood as number of character in utf-8 encoding. The proper function is now used instead. Change-Id: Ie5ad77a31914298460d38a410b6b01906dcde32d --- diff --git a/clock/src/Utils/Time.cpp b/clock/src/Utils/Time.cpp index 4750560..0c3846d 100644 --- a/clock/src/Utils/Time.cpp +++ b/clock/src/Utils/Time.cpp @@ -114,15 +114,17 @@ I18nString::~I18nString() std::string I18nString::std_string() const { std::string str; - size_t new_size = i18n_ustring_get_length(data_); - if (get_last_result() != I18N_ERROR_NONE) { - FAT("i18n_ustring_copy_ua_n failed"); + i18n_error_code_e error = I18N_ERROR_NONE; + int32_t new_size; + i18n_ustring_to_UTF8(nullptr, 0, &new_size, data_, -1, &error); + if ((error != I18N_ERROR_NONE) && (error != I18N_ERROR_BUFFER_OVERFLOW)) { + FAT("i18n_ustring_to_UTF8 failed: %s", get_error_message(error)); } str.reserve(new_size + 1); str.resize(new_size); - i18n_ustring_copy_au(&str[0], data_); - if (get_last_result() != I18N_ERROR_NONE) { - FAT("i18n_ustring_copy_ua_n failed"); + i18n_ustring_to_UTF8(&str[0], str.capacity(), &new_size, data_, -1, &error); + if (error != I18N_ERROR_NONE) { + FAT("i18n_ustring_to_UTF8 failed: %s", get_error_message(error)); } return str; }