Fix privilege info 03/122503/9
authorZofia Abramowska <z.abramowska@samsung.com>
Sun, 2 Apr 2017 12:50:26 +0000 (14:50 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 3 Apr 2017 18:53:11 +0000 (20:53 +0200)
* Fix possible incorrect memory access (use after free)
* Don't throw when privilege_info fails, return input parameter
instead (behave like dgettext)

Change-Id: Ia3ef07e06282a88c39d9a6dd98644f5bbda40dc9

src/common/policy/PrivilegeInfo.cpp

index 1ab529e39d52d85e5cb190a71c24dceb404bbdc7..06d65b74440fe6201fec2fff09a028d3afc5e10a 100644 (file)
@@ -49,7 +49,7 @@ std::string getPrivacyDisplayName(const std::string &privilege) {
         return privilege;
     }
     std::unique_ptr<char, decltype(free)*> displaNamePtr(displayName, free);
-    return displayName;
+    return std::string(displayName);
 }
 
 std::string getPrivacyName(const std::string &privilege) {
@@ -57,19 +57,20 @@ std::string getPrivacyName(const std::string &privilege) {
     int ret = privilege_info_get_privacy_by_privilege(privilege.c_str(), &privacyName);
     if (ret != PRVMGR_ERR_NONE || !privacyName) {
         ALOGE("Unable to get privacy group for privilege: <" << privilege << ">, err: <" << ret << ">");
-        throw Exception("Can't get privacy group name for privilege " + privilege);
+        return privilege;
     }
 
     std::unique_ptr<char, decltype(free) *> privacyNamePtr(privacyName, free);
-    return privacyName;
+    return std::string(privacyName);
 }
+
 std::vector<std::string> getPrivacyPrivileges(const std::string &privacy) {
     GList *privilegeList = nullptr;
 
     int ret = privilege_info_get_privilege_list_by_privacy(privacy.c_str(), &privilegeList);
     if (ret != PRVMGR_ERR_NONE || !privilegeList) {
         ALOGE("Unable to get privacy group list of privileges; err: <" << ret <<  ">" );
-        return {};
+        return {privacy};
     }
 
     GListWrap privList(privilegeList);