Fix bug of debug mode installation of hybrid package 99/200899/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 5 Mar 2019 11:53:12 +0000 (20:53 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 5 Mar 2019 11:56:27 +0000 (11:56 +0000)
The appdebugging privilege should be added for all applications
included in hybrid package.

Change-Id: Id0bced11063f7fb8c66b4a10ac696c5832f0acc7
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/step/security/step_privilege_compatibility.cc

index 3a2029ade68957dd52b37f155e8217025527aa73..a1f12ab758e71c33f35c6e26d9aa914c01a4b1e5 100644 (file)
@@ -107,6 +107,21 @@ bool TranslatePrivilegesForCompatibility(manifest_x* m) {
   return true;
 }
 
+bool AppendPrivilegeToList(const char* type, const char* privilege_str,
+    GList** list) {
+  privilege_x* privilege =
+      reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+  if (!privilege) {
+    LOG(ERROR) << "Out of memory";
+    return false;
+  }
+  privilege->type = strdup(type);
+  privilege->value = strdup(privilege_str);
+  *list = g_list_append(*list, privilege);
+
+  return true;
+}
+
 }  // namespace
 
 namespace common_installer {
@@ -128,44 +143,28 @@ Step::Status StepPrivilegeCompatibility::process() {
 
   if (internal_priv_type_ == InternalPrivType::TPK ||
       internal_priv_type_ == InternalPrivType::BOTH) {
-    privilege_x* privilege =
-        reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
-    if (!privilege) {
-      LOG(ERROR) << "Out of memory";
+    if (!AppendPrivilegeToList(kNativePrivilegeType, internal_priv.c_str(),
+        &context_->manifest_data.get()->privileges))
       return Step::Status::ERROR;
+    if (context_->debug_mode.get()) {
+      if (!AppendPrivilegeToList(kNativePrivilegeType,
+              kAppDebuggingPrivilegeStr,
+              &context_->manifest_data.get()->privileges))
+        return Step::Status::ERROR;
     }
-    privilege->type = strdup(kNativePrivilegeType);
-    privilege->value = strdup(internal_priv.c_str());
-    context_->manifest_data.get()->privileges =
-        g_list_append(context_->manifest_data.get()->privileges, privilege);
   }
 
   if (internal_priv_type_ == InternalPrivType::WGT ||
       internal_priv_type_ == InternalPrivType::BOTH) {
-    privilege_x* privilege =
-        reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
-    if (!privilege) {
-      LOG(ERROR) << "Out of memory";
-      return Step::Status::ERROR;
-    }
-    privilege->type = strdup(kWebPrivilegeType);
-    privilege->value = strdup(internal_priv.c_str());
-    context_->manifest_data.get()->privileges =
-        g_list_append(context_->manifest_data.get()->privileges, privilege);
-  }
-
-  if (context_->debug_mode.get()) {
-    privilege_x* privilege =
-        reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
-    if (!privilege) {
-      LOG(ERROR) << "Out of memory";
+    if (!AppendPrivilegeToList(kWebPrivilegeType, internal_priv.c_str(),
+            &context_->manifest_data.get()->privileges))
       return Step::Status::ERROR;
+    if (context_->debug_mode.get()) {
+      if (!AppendPrivilegeToList(kWebPrivilegeType,
+              kAppDebuggingPrivilegeStr,
+              &context_->manifest_data.get()->privileges))
+        return Step::Status::ERROR;
     }
-    privilege->type = internal_priv_type_ == InternalPrivType::TPK ?
-        strdup(kNativePrivilegeType) : strdup(kWebPrivilegeType);
-    privilege->value = strdup(kAppDebuggingPrivilegeStr);
-    context_->manifest_data.get()->privileges =
-        g_list_append(context_->manifest_data.get()->privileges, privilege);
   }
 
   return TranslatePrivilegesForCompatibility(context_->manifest_data.get()) ?