Program: 191928
Project: 191928
Buggy source:
private void replacePackageLIF(PackageParser.Package pkg,final int policyFlags,int scanFlags,UserHandle user,String installerPackageName,PackageInstalledInfo res){
  final boolean isEphemeral=(policyFlags & PackageParser.PARSE_IS_EPHEMERAL) != 0;
  final PackageParser.Package oldPackage;
  final String pkgName=pkg.packageName;
  final int[] allUsers;
synchronized (mPackages) {
    oldPackage=mPackages.get(pkgName);
    final boolean oldIsEphemeral=oldPackage.applicationInfo.isEphemeralApp();
    if (isEphemeral && !oldIsEphemeral) {
      Slog.w(TAG,"String_Node_Str" + pkgName);
      res.setReturnCode(PackageManager.INSTALL_FAILED_EPHEMERAL_INVALID);
      return;
    }
    if (DEBUG_INSTALL)     Slog.d(TAG,"String_Node_Str" + pkg + "String_Node_Str"+ oldPackage);
    final PackageSetting ps=mSettings.mPackages.get(pkgName);
    if (shouldCheckUpgradeKeySetLP(ps,scanFlags)) {
      if (!checkUpgradeKeySetLP(ps,pkg)) {
        res.setError(INSTALL_FAILED_UPDATE_INCOMPATIBLE,"String_Node_Str" + pkgName);
        return;
      }
    }
 else {
      if (compareSignatures(oldPackage.mSignatures,pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) {
        res.setError(INSTALL_FAILED_UPDATE_INCOMPATIBLE,"String_Node_Str" + pkgName);
        return;
      }
    }
    String invalidPackageName=getParentOrChildPackageChangedSharedUser(oldPackage,pkg);
    if (invalidPackageName != null) {
      res.setError(INSTALL_FAILED_SHARED_USER_INCOMPATIBLE,"String_Node_Str" + invalidPackageName + "String_Node_Str"+ oldPackage.mSharedUserId);
      return;
    }
    allUsers=sUserManager.getUserIds();
  }
  res.removedInfo=new PackageRemovedInfo();
  res.removedInfo.uid=oldPackage.applicationInfo.uid;
  res.removedInfo.removedPackage=oldPackage.packageName;
  res.removedInfo.isUpdate=true;
  final int childCount=(oldPackage.childPackages != null) ? oldPackage.childPackages.size() : 0;
  for (int i=0; i < childCount; i++) {
    boolean childPackageUpdated=false;
    PackageParser.Package childPkg=oldPackage.childPackages.get(i);
    if (res.addedChildPackages != null) {
      PackageInstalledInfo childRes=res.addedChildPackages.get(childPkg.packageName);
      if (childRes != null) {
        childRes.removedInfo.uid=childPkg.applicationInfo.uid;
        childRes.removedInfo.removedPackage=childPkg.packageName;
        childRes.removedInfo.isUpdate=true;
        childPackageUpdated=true;
      }
    }
    if (!childPackageUpdated) {
      PackageRemovedInfo childRemovedRes=new PackageRemovedInfo();
      childRemovedRes.removedPackage=childPkg.packageName;
      childRemovedRes.isUpdate=false;
      childRemovedRes.dataRemoved=true;
synchronized (mPackages) {
        PackageSetting childPs=mSettings.peekPackageLPr(childPkg.packageName);
        if (childPs != null) {
          childRemovedRes.origUsers=childPs.queryInstalledUsers(allUsers,true);
        }
      }
      if (res.removedInfo.removedChildPackages == null) {
        res.removedInfo.removedChildPackages=new ArrayMap<>();
      }
      res.removedInfo.removedChildPackages.put(childPkg.packageName,childRemovedRes);
    }
  }
  boolean sysPkg=(isSystemApp(oldPackage));
  if (sysPkg) {
    final boolean privileged=(oldPackage.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
    final int systemPolicyFlags=policyFlags | PackageParser.PARSE_IS_SYSTEM | (privileged ? PackageParser.PARSE_IS_PRIVILEGED : 0);
    replaceSystemPackageLIF(oldPackage,pkg,systemPolicyFlags,scanFlags,user,allUsers,installerPackageName,res);
  }
 else {
    replaceNonSystemPackageLIF(oldPackage,pkg,policyFlags,scanFlags,user,allUsers,installerPackageName,res);
  }
}

Fixed version (ground truth):
private void replacePackageLIF(PackageParser.Package pkg,final int policyFlags,int scanFlags,UserHandle user,String installerPackageName,PackageInstalledInfo res){
  final boolean isEphemeral=(policyFlags & PackageParser.PARSE_IS_EPHEMERAL) != 0;
  final PackageParser.Package oldPackage;
  final String pkgName=pkg.packageName;
  final int[] allUsers;
  final int[] installedUsers;
synchronized (mPackages) {
    oldPackage=mPackages.get(pkgName);
    final boolean oldIsEphemeral=oldPackage.applicationInfo.isEphemeralApp();
    if (isEphemeral && !oldIsEphemeral) {
      Slog.w(TAG,"String_Node_Str" + pkgName);
      res.setReturnCode(PackageManager.INSTALL_FAILED_EPHEMERAL_INVALID);
      return;
    }
    if (DEBUG_INSTALL)     Slog.d(TAG,"String_Node_Str" + pkg + "String_Node_Str"+ oldPackage);
    final PackageSetting ps=mSettings.mPackages.get(pkgName);
    if (shouldCheckUpgradeKeySetLP(ps,scanFlags)) {
      if (!checkUpgradeKeySetLP(ps,pkg)) {
        res.setError(INSTALL_FAILED_UPDATE_INCOMPATIBLE,"String_Node_Str" + pkgName);
        return;
      }
    }
 else {
      if (compareSignatures(oldPackage.mSignatures,pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) {
        res.setError(INSTALL_FAILED_UPDATE_INCOMPATIBLE,"String_Node_Str" + pkgName);
        return;
      }
    }
    String invalidPackageName=getParentOrChildPackageChangedSharedUser(oldPackage,pkg);
    if (invalidPackageName != null) {
      res.setError(INSTALL_FAILED_SHARED_USER_INCOMPATIBLE,"String_Node_Str" + invalidPackageName + "String_Node_Str"+ oldPackage.mSharedUserId);
      return;
    }
    allUsers=sUserManager.getUserIds();
    installedUsers=ps.queryInstalledUsers(allUsers,true);
  }
  res.removedInfo=new PackageRemovedInfo();
  res.removedInfo.uid=oldPackage.applicationInfo.uid;
  res.removedInfo.removedPackage=oldPackage.packageName;
  res.removedInfo.isUpdate=true;
  res.removedInfo.origUsers=installedUsers;
  final int childCount=(oldPackage.childPackages != null) ? oldPackage.childPackages.size() : 0;
  for (int i=0; i < childCount; i++) {
    boolean childPackageUpdated=false;
    PackageParser.Package childPkg=oldPackage.childPackages.get(i);
    if (res.addedChildPackages != null) {
      PackageInstalledInfo childRes=res.addedChildPackages.get(childPkg.packageName);
      if (childRes != null) {
        childRes.removedInfo.uid=childPkg.applicationInfo.uid;
        childRes.removedInfo.removedPackage=childPkg.packageName;
        childRes.removedInfo.isUpdate=true;
        childPackageUpdated=true;
      }
    }
    if (!childPackageUpdated) {
      PackageRemovedInfo childRemovedRes=new PackageRemovedInfo();
      childRemovedRes.removedPackage=childPkg.packageName;
      childRemovedRes.isUpdate=false;
      childRemovedRes.dataRemoved=true;
synchronized (mPackages) {
        PackageSetting childPs=mSettings.peekPackageLPr(childPkg.packageName);
        if (childPs != null) {
          childRemovedRes.origUsers=childPs.queryInstalledUsers(allUsers,true);
        }
      }
      if (res.removedInfo.removedChildPackages == null) {
        res.removedInfo.removedChildPackages=new ArrayMap<>();
      }
      res.removedInfo.removedChildPackages.put(childPkg.packageName,childRemovedRes);
    }
  }
  boolean sysPkg=(isSystemApp(oldPackage));
  if (sysPkg) {
    final boolean privileged=(oldPackage.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
    final int systemPolicyFlags=policyFlags | PackageParser.PARSE_IS_SYSTEM | (privileged ? PackageParser.PARSE_IS_PRIVILEGED : 0);
    replaceSystemPackageLIF(oldPackage,pkg,systemPolicyFlags,scanFlags,user,allUsers,installerPackageName,res);
  }
 else {
    replaceNonSystemPackageLIF(oldPackage,pkg,policyFlags,scanFlags,user,allUsers,installerPackageName,res);
  }
}