From: Hwankyu Jhun Date: Wed, 13 Oct 2021 04:36:58 +0000 (+0900) Subject: Fix exception handlings of getter X-Git-Tag: submit/tizen/20211110.074819~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F28%2F265228%2F2;p=platform%2Fcore%2Fapi%2Fpreference.git Fix exception handlings of getter Even though the type is not equal to the request type, the method returns the value with the error result. After this patch is applied, the method checks whether the size of the raw data greater than the size or not. If the type is boolean, the method checks the size of the raw data is greater than the integer size or not.(This is for backward compatibility.) Change-Id: I6288710d9ad79d22f8fa45fc50f77fc7245811a8 Signed-off-by: Hwankyu Jhun --- diff --git a/preference/preference-internal.cc b/preference/preference-internal.cc index 8804023..b1b29c8 100644 --- a/preference/preference-internal.cc +++ b/preference/preference-internal.cc @@ -63,6 +63,9 @@ int Preference::GetInt(const std::string& key) { _E("The type(%d) of keynode(%s) is not integer", static_cast(type), key.c_str()); set_last_result(PREFERENCE_ERROR_INVALID_PARAMETER); + auto& raw = d->GetRaw(); + if (raw.size() == 0 || raw.size() > sizeof(int)) + THROW(PREFERENCE_ERROR_INVALID_PARAMETER); } return d->GetInt(); @@ -80,6 +83,9 @@ double Preference::GetDouble(const std::string& key) { _E("The type(%d) of keynode(%s) is not double", static_cast(type), key.c_str()); set_last_result(PREFERENCE_ERROR_INVALID_PARAMETER); + auto& raw = d->GetRaw(); + if (raw.size() == 0 || raw.size() > sizeof(double)) + THROW(PREFERENCE_ERROR_INVALID_PARAMETER); } return d->GetDouble(); @@ -96,7 +102,7 @@ std::string Preference::GetString(const std::string& key) { } else { _E("The type(%d) of keynode(%s) is not string", static_cast(type), key.c_str()); - set_last_result(PREFERENCE_ERROR_INVALID_PARAMETER); + THROW(PREFERENCE_ERROR_INVALID_PARAMETER); } return d->GetString(); @@ -114,6 +120,9 @@ bool Preference::GetBoolean(const std::string& key) { _E("The type(%d) of keynode(%s) is not boolean", static_cast(type), key.c_str()); set_last_result(PREFERENCE_ERROR_INVALID_PARAMETER); + auto& raw = d->GetRaw(); + if (raw.size() == 0 || raw.size() > sizeof(int)) + THROW(PREFERENCE_ERROR_INVALID_PARAMETER); } return d->GetBoolean();