Security plugin: pkg_name allocation in conflict
authorElena Reshetova <elena.reshetova@intel.com>
Tue, 23 Jul 2013 13:37:05 +0000 (16:37 +0300)
committerAnas Nashif <anas.nashif@intel.com>
Mon, 5 Aug 2013 16:53:17 +0000 (12:53 -0400)
- fix to the pkg_name allocation in conflict handling

plugins/msm-plugin.c

index f921329..4cb5ec3 100644 (file)
@@ -209,14 +209,15 @@ rpmRC PLUGINHOOK_FILE_CONFLICT_FUNC(rpmts ts, char* path,
 {
     fileconflict *fc;
     if (!path)
-        return rpmrc; 
+        return rpmrc;
+
     rpmlog(RPMLOG_DEBUG, "FILE_CONFLICT_FUNC hook  path %s\n",path);
 
-    const char *name = headerGetString(oldHeader, RPMTAG_SECSWSOURCE);    
-    if (!name || !root) {
-        return rpmrc; /* no sw source(s) - abnormal state */
-    }
+    const char *name = headerGetString(oldHeader, RPMTAG_SECSWSOURCE);
     const char *pkg_name = headerGetString(oldHeader, RPMTAG_NAME);
+    if (!name || !root || !pkg_name) {
+        return rpmrc; /* no sw source(s) or package name - abnormal state */
+    }
 
     sw_source_x *sw_source = msmSWSourceTreeTraversal(root->sw_sources, findSWSourceByName, (void *)name, NULL);
     if (!sw_source)
@@ -229,7 +230,8 @@ rpmRC PLUGINHOOK_FILE_CONFLICT_FUNC(rpmts ts, char* path,
         if (!fc) return RPMRC_FAIL;
         fc->path = path;
         fc->sw_source = sw_source;
-        fc->pkg_name = pkg_name;
+        fc->pkg_name = strdup(pkg_name);
+        if (!fc->pkg_name) return RPMRC_FAIL;
         HASH_ADD_KEYPTR(hh, allfileconflicts, path, strlen(path), fc);
     } else {
         /* Many packages have installed the same file */
@@ -830,6 +832,7 @@ rpmRC PLUGINHOOK_CLEANUP_FUNC(void)
         HASH_ITER(hh, allfileconflicts, fc, temp) {
             HASH_DELETE(hh, allfileconflicts, fc);
             msmFreePointer((void**)&fc->path);
+            msmFreePointer((void**)&fc->pkg_name);
             msmFreePointer((void**)&fc);
         }
     }