Fix memory allocation in TranslatePrivilegesForCompatibility 51/48451/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 21 Sep 2015 13:23:06 +0000 (15:23 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Wed, 23 Sep 2015 09:12:34 +0000 (02:12 -0700)
Change-Id: I03e8b8a1685ef89389ab51a826e0a6f1958da2ef

src/common/step/step_privilege_compatibility.cc
src/wgt/step/step_parse.cc

index 3405e86..bd776e7 100644 (file)
@@ -31,14 +31,19 @@ bool TranslatePrivilegesForCompatibility(const std::string& pkg_type, manifest_x
   if (pkg_type == "wgt") {
     if (!m->privileges) {
       m->privileges =
-        reinterpret_cast<privileges_x*>(calloc(1, sizeof(privileges_x*)));
+        reinterpret_cast<privileges_x*>(calloc(1, sizeof(privileges_x)));
     }
     privilege_x* priv =
-      reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x*)));
+      reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
     priv->text = strdup(kDefaultPrivilegeForWebApp);
     LISTADD(m->privileges->privilege, priv);
   }
 
+  // No privileges to map
+  if (!m->privileges) {
+    return true;
+  }
+
   // calculate number of privileges
   size_t size = 0;
   privileges_x *privileges = nullptr;
index 02d7a96..a27653d 100755 (executable)
@@ -321,8 +321,8 @@ common_installer::Step::Status StepParse::process() {
     }
   }
 
-  const manifest_x* manifest = context_->manifest_data.get();
-  if (!FillManifestX(const_cast<manifest_x*>(manifest))) {
+  manifest_x* manifest = context_->manifest_data.get();
+  if (!FillManifestX(manifest)) {
     LOG(ERROR) << "[Parse] Storing manifest_x failed. "
                <<  parser_->GetErrorMessage();
     return common_installer::Step::Status::ERROR;