Program: 197180
Project: 197180
Buggy source:
private void updatePermissionsLPw(String changingPkg,PackageParser.Package pkgInfo,int flags){
  Iterator<BasePermission> it=mSettings.mPermissionTrees.values().iterator();
  while (it.hasNext()) {
    final BasePermission bp=it.next();
    if (bp.packageSetting == null) {
      bp.packageSetting=mSettings.mPackages.get(bp.sourcePackage);
    }
    if (bp.packageSetting == null) {
      Slog.w(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
      it.remove();
    }
 else     if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
      if (pkgInfo == null || !hasPermission(pkgInfo,bp.name)) {
        Slog.i(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
        flags|=UPDATE_PERMISSIONS_ALL;
        it.remove();
      }
    }
  }
  it=mSettings.mPermissions.values().iterator();
  while (it.hasNext()) {
    final BasePermission bp=it.next();
    if (bp.type == BasePermission.TYPE_DYNAMIC) {
      if (DEBUG_SETTINGS)       Log.v(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage+ "String_Node_Str"+ bp.pendingInfo);
      if (bp.packageSetting == null && bp.pendingInfo != null) {
        final BasePermission tree=findPermissionTreeLP(bp.name);
        if (tree != null && tree.perm != null) {
          bp.packageSetting=tree.packageSetting;
          bp.perm=new PackageParser.Permission(tree.perm.owner,new PermissionInfo(bp.pendingInfo));
          bp.perm.info.packageName=tree.perm.info.packageName;
          bp.perm.info.name=bp.name;
          bp.uid=tree.uid;
        }
      }
    }
    if (bp.packageSetting == null) {
      bp.packageSetting=mSettings.mPackages.get(bp.sourcePackage);
    }
    if (bp.packageSetting == null) {
      Slog.w(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
      it.remove();
    }
 else     if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
      if (pkgInfo == null || !hasPermission(pkgInfo,bp.name)) {
        Slog.i(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
        flags|=UPDATE_PERMISSIONS_ALL;
        it.remove();
      }
    }
  }
  if ((flags & UPDATE_PERMISSIONS_ALL) != 0) {
    for (    PackageParser.Package pkg : mPackages.values()) {
      if (pkg != pkgInfo) {
        grantPermissionsLPw(pkg,(flags & UPDATE_PERMISSIONS_REPLACE_ALL) != 0);
      }
    }
  }
  if (pkgInfo != null) {
    grantPermissionsLPw(pkgInfo,(flags & UPDATE_PERMISSIONS_REPLACE_PKG) != 0);
  }
}

Fixed version (ground truth):
private void updatePermissionsLPw(String changingPkg,PackageParser.Package pkgInfo,int flags){
  Iterator<BasePermission> it=mSettings.mPermissionTrees.values().iterator();
  while (it.hasNext()) {
    final BasePermission bp=it.next();
    if (bp.packageSetting == null) {
      bp.packageSetting=mSettings.mPackages.get(bp.sourcePackage);
    }
    if (bp.packageSetting == null) {
      Slog.w(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
      it.remove();
    }
 else     if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
      if (pkgInfo == null || !hasPermission(pkgInfo,bp.name)) {
        Slog.i(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
        flags|=UPDATE_PERMISSIONS_ALL;
        it.remove();
      }
    }
  }
  it=mSettings.mPermissions.values().iterator();
  while (it.hasNext()) {
    final BasePermission bp=it.next();
    if (bp.type == BasePermission.TYPE_DYNAMIC) {
      if (DEBUG_SETTINGS)       Log.v(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage+ "String_Node_Str"+ bp.pendingInfo);
      if (bp.packageSetting == null && bp.pendingInfo != null) {
        final BasePermission tree=findPermissionTreeLP(bp.name);
        if (tree != null && tree.perm != null) {
          bp.packageSetting=tree.packageSetting;
          bp.perm=new PackageParser.Permission(tree.perm.owner,new PermissionInfo(bp.pendingInfo));
          bp.perm.info.packageName=tree.perm.info.packageName;
          bp.perm.info.name=bp.name;
          bp.uid=tree.uid;
        }
      }
    }
    if (bp.packageSetting == null) {
      bp.packageSetting=mSettings.mPackages.get(bp.sourcePackage);
    }
    if (bp.packageSetting == null) {
      Slog.w(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
      it.remove();
    }
 else     if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
      if (pkgInfo == null || !hasPermission(pkgInfo,bp.name)) {
        Slog.i(TAG,"String_Node_Str" + bp.name + "String_Node_Str"+ bp.sourcePackage);
        flags|=UPDATE_PERMISSIONS_ALL;
        it.remove();
      }
    }
  }
  if ((flags & UPDATE_PERMISSIONS_ALL) != 0) {
    for (    PackageParser.Package pkg : mPackages.values()) {
      if (pkg != pkgInfo) {
        grantPermissionsLPw(pkg,(flags & UPDATE_PERMISSIONS_REPLACE_ALL) != 0,changingPkg);
      }
    }
  }
  if (pkgInfo != null) {
    grantPermissionsLPw(pkgInfo,(flags & UPDATE_PERMISSIONS_REPLACE_PKG) != 0,changingPkg);
  }
}