/** * Check to ensure that this context is not the result of recursion. */ public void checkForRecursion() throws CFGBuilderException { Context callerContext = caller; while (callerContext != null) { if (callerContext.subroutine == this.subroutine) { throw new CFGBuilderException("JSR recursion detected!"); } callerContext = callerContext.caller; } } }
private Map<String, List<Location>> get_line_location(Method m, ClassContext classContext){ HashMap<String, List<Location>> all_line_location = new HashMap<>(); ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = null; try { cfg = classContext.getCFG(m); } catch (CFGBuilderException e) { e.printStackTrace(); return all_line_location; } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location loc = i.next(); Instruction inst = loc.getHandle().getInstruction(); if(inst instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) inst; // if (classname.equals(invoke.getClassName(cpg)) && // methodName.equals(invoke.getMethodName(cpg))) { if(all_line_location.containsKey(invoke.getMethodName(cpg))){ all_line_location.get(invoke.getMethodName(cpg)).add(loc); }else { LinkedList<Location> loc_list = new LinkedList<>(); loc_list.add(loc); all_line_location.put(invoke.getMethodName(cpg), loc_list); } // } } } return all_line_location; }
private void allow_All_Hostname_Verify(ClassContext classContext, JavaClass javaClass, Method m){ ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = null; try { cfg = classContext.getCFG(m); } catch (CFGBuilderException e) { e.printStackTrace(); } for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) { Location loc = i.next(); //ByteCode.printOpCode(loc.getHandle().getInstruction(), cpg); Instruction inst = loc.getHandle().getInstruction(); if (inst instanceof GETSTATIC) { GETSTATIC invoke = (GETSTATIC) inst; // System.out.println(invoke.getClassName(cpg)); // System.out.println(invoke.getName(cpg)); // System.out.println(invoke.getSignature(cpg)); // if("org.apache.http.conn.ssl.SSLSocketFactory".equals(invoke.getClassName(cpg)) && // "Lorg/apache/http/conn/ssl/X509HostnameVerifier;".equals(invoke.getSignature(cpg)) && // "ALLOW_ALL_HOSTNAME_VERIFIER".equals(invoke.getName(cpg))){ if("ALLOW_ALL_HOSTNAME_VERIFIER".equals(invoke.getName(cpg))){ bugReporter.reportBug(new BugInstance(this, WEAK_HOSTNAME_VERIFIER_TYPE, Priorities.NORMAL_PRIORITY) .addClassAndMethod(javaClass, m)); } } } }
/** * Add an instruction to the subroutine. We keep track of which * instructions are part of which subroutines. No instruction may be * part of more than one subroutine. * * @param handle * the instruction to be added to the subroutine */ public void addInstruction(InstructionHandle handle) throws CFGBuilderException { int position = handle.getPosition(); if (usedInstructionSet.get(position)) { throw new CFGBuilderException("Instruction " + handle + " visited in multiple subroutines"); } instructionSet.set(position); usedInstructionSet.set(position); }
InstructionHandle next = handle.getNext(); if (next == null) { throw new CFGBuilderException("Control falls off end of method: " + handle);
throw new CFGBuilderException("Invalid stack at "+prev+" when checking "+handle);
throw new CFGBuilderException("Unknown caller for escape target " + targetInstruction + " referenced by " + context.getSubroutine().getStartInstruction());
/** * Check to ensure that this context is not the result of recursion. */ public void checkForRecursion() throws CFGBuilderException { Context callerContext = caller; while (callerContext != null) { if (callerContext.subroutine == this.subroutine) { throw new CFGBuilderException("JSR recursion detected!"); } callerContext = callerContext.caller; } } }
/** * Add an instruction to the subroutine. We keep track of which * instructions are part of which subroutines. No instruction may be * part of more than one subroutine. * * @param handle * the instruction to be added to the subroutine */ public void addInstruction(InstructionHandle handle) throws CFGBuilderException { int position = handle.getPosition(); if (usedInstructionSet.get(position)) { throw new CFGBuilderException("Instruction " + handle + " visited in multiple subroutines"); } instructionSet.set(position); usedInstructionSet.set(position); }
InstructionHandle next = handle.getNext(); if (next == null) { throw new CFGBuilderException("Control falls off end of method: " + handle);
throw new CFGBuilderException("Invalid stack at "+prev+" when checking "+handle);
throw new CFGBuilderException("Unknown caller for escape target " + targetInstruction + " referenced by " + context.getSubroutine().getStartInstruction());