<commit_before>/*******************************************************************************
 * Copyright (c) 2012 Secure Software Engineering Group at EC SPRIDE.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors: <NAME>, <NAME>, <NAME>, <NAME>, and others.
 ******************************************************************************/
package soot.jimple.infoflow.problems;

import heros.InterproceduralCFG;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import soot.ArrayType;
import soot.IntType;
import soot.LongType;
import soot.PrimType;
import soot.RefType;
import soot.Scene;
import soot.SootClass;
import soot.SootMethod;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.jimple.ArrayRef;
import soot.jimple.Constant;
import soot.jimple.InstanceFieldRef;
import soot.jimple.infoflow.data.Abstraction;
import soot.jimple.infoflow.data.AccessPath;
import soot.jimple.infoflow.handlers.TaintPropagationHandler;
import soot.jimple.infoflow.nativ.DefaultNativeCallHandler;
import soot.jimple.infoflow.nativ.NativeCallHandler;
import soot.jimple.infoflow.solver.IInfoflowCFG;
import soot.jimple.infoflow.solver.IInfoflowSolver;
import soot.jimple.infoflow.taintWrappers.ITaintPropagationWrapper;
import soot.jimple.infoflow.util.DataTypeHandler;
import soot.jimple.toolkits.ide.DefaultJimpleIFDSTabulationProblem;
/**
 * abstract super class which 
 * 	- concentrates functionality used by InfoflowProblem and BackwardsInfoflowProblem
 *  - contains helper functions which should not pollute the naturally large InfofflowProblems
 *
 */
public abstract class AbstractInfoflowProblem extends DefaultJimpleIFDSTabulationProblem<Abstraction, InterproceduralCFG<Unit, SootMethod>> {

	protected final Map<Unit, Set<Abstraction>> initialSeeds = new HashMap<Unit, Set<Abstraction>>();
	protected ITaintPropagationWrapper taintWrapper;
	protected NativeCallHandler ncHandler = new DefaultNativeCallHandler();
	
	protected boolean enableImplicitFlows = false;
	protected boolean enableStaticFields = true;
	protected boolean enableExceptions = true;
	protected boolean flowSensitiveAliasing = true;

	protected boolean inspectSources = true;
	protected boolean inspectSinks = true;

	Abstraction zeroValue = null;
	
	protected IInfoflowSolver solver = null;
	
	protected boolean stopAfterFirstFlow = false;
	
	protected Set<TaintPropagationHandler> taintPropagationHandlers = new HashSet<TaintPropagationHandler>();
	
	public AbstractInfoflowProblem(InterproceduralCFG<Unit, SootMethod> icfg) {
		super(icfg);
	}
	
	protected boolean canCastType(Type destType, Type sourceType) {
		if (Scene.v().getFastHierarchy().canStoreType(destType, sourceType) // cast-up, i.e. Object to String
				|| Scene.v().getFastHierarchy().canStoreType(sourceType, destType)) // cast-down, i.e. String to Object
			return true;
		
		if (destType instanceof PrimType && sourceType instanceof PrimType)
			if (sourceType instanceof LongType && destType instanceof IntType
					|| destType instanceof LongType && sourceType instanceof IntType)
				return true;
			
		return false;
	}
		
	protected boolean hasCompatibleTypesForCall(AccessPath apBase, SootClass dest) {
		// Cannot invoke a method on a primitive type
		if (apBase.getType() instanceof PrimType)
			return false;<commit_msg>fixed a NullPointerExeption<commit_after>/*******************************************************************************
 * Copyright (c) 2012 Secure Software Engineering Group at EC SPRIDE.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors: <NAME>, <NAME>, <NAME>, <NAME>, and others.
 ******************************************************************************/
package soot.jimple.infoflow.problems;

import heros.InterproceduralCFG;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import soot.ArrayType;
import soot.IntType;
import soot.LongType;
import soot.PrimType;
import soot.RefType;
import soot.Scene;
import soot.SootClass;
import soot.SootMethod;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.jimple.ArrayRef;
import soot.jimple.Constant;
import soot.jimple.InstanceFieldRef;
import soot.jimple.infoflow.data.Abstraction;
import soot.jimple.infoflow.data.AccessPath;
import soot.jimple.infoflow.handlers.TaintPropagationHandler;
import soot.jimple.infoflow.nativ.DefaultNativeCallHandler;
import soot.jimple.infoflow.nativ.NativeCallHandler;
import soot.jimple.infoflow.solver.IInfoflowCFG;
import soot.jimple.infoflow.solver.IInfoflowSolver;
import soot.jimple.infoflow.taintWrappers.ITaintPropagationWrapper;
import soot.jimple.infoflow.util.DataTypeHandler;
import soot.jimple.toolkits.ide.DefaultJimpleIFDSTabulationProblem;
/**
 * abstract super class which 
 * 	- concentrates functionality used by InfoflowProblem and BackwardsInfoflowProblem
 *  - contains helper functions which should not pollute the naturally large InfofflowProblems
 *
 */
public abstract class AbstractInfoflowProblem extends DefaultJimpleIFDSTabulationProblem<Abstraction, InterproceduralCFG<Unit, SootMethod>> {

	protected final Map<Unit, Set<Abstraction>> initialSeeds = new HashMap<Unit, Set<Abstraction>>();
	protected ITaintPropagationWrapper taintWrapper;
	protected NativeCallHandler ncHandler = new DefaultNativeCallHandler();
	
	protected boolean enableImplicitFlows = false;
	protected boolean enableStaticFields = true;
	protected boolean enableExceptions = true;
	protected boolean flowSensitiveAliasing = true;

	protected boolean inspectSources = true;
	protected boolean inspectSinks = true;

	Abstraction zeroValue = null;
	
	protected IInfoflowSolver solver = null;
	
	protected boolean stopAfterFirstFlow = false;
	
	protected Set<TaintPropagationHandler> taintPropagationHandlers = new HashSet<TaintPropagationHandler>();
	
	public AbstractInfoflowProblem(InterproceduralCFG<Unit, SootMethod> icfg) {
		super(icfg);
	}
	
	protected boolean canCastType(Type destType, Type sourceType) {
		// If we don't have a source type, we generally allow the cast
		if (sourceType == null)
			return true;
		
		if (Scene.v().getFastHierarchy().canStoreType(destType, sourceType) // cast-up, i.e. Object to String
				|| Scene.v().getFastHierarchy().canStoreType(sourceType, destType)) // cast-down, i.e. String to Object
			return true;
		
		if (destType instanceof PrimType && sourceType instanceof PrimType)
			if (sourceType instanceof LongType && destType instanceof IntType
					|| destType instanceof LongType && sourceType instanceof IntType)
				return true;
			
		return false;
	}
		
	protected boolean hasCompatibleTypesForCall(AccessPath apBase, SootClass dest) {
		// Cannot invoke a method on a primitive type
		if (apBase.getType() instanceof PrimType)
			return false;
{'fraction_non_alphanumeric': 0.12279492833517089, 'fraction_numerical': 0.002205071664829107, 'mean_word_length': 5.833333333333333, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3401563', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2034, 'n_words': 554}