@Override public InstructionHandle next() throws NoSuchElementException { if (!hasNext()) { throw new NoSuchElementException(); } InstructionHandle result = next; next = (result == first) ? null : next.getPrev(); return result; }
/** * Get the predecessor of given instruction within the basic block. * * @param handle * the instruction * @return the instruction's predecessor, or null if the instruction is the * first in the basic block */ public InstructionHandle getPredecessorOf(InstructionHandle handle) { if (VERIFY_INTEGRITY) { if (!containsInstruction(handle)) { throw new IllegalStateException(); } } return handle == firstInstruction ? null : handle.getPrev(); }
/** * Get the previous instruction matching the given type of instruction (second parameter) * * @param startHandle Location to start from * @param clazz Type of instruction to look for * @return The instruction found (null if not found) */ public static <T> T getPrevInstruction(InstructionHandle startHandle, Class<T> clazz) { InstructionHandle curHandle = startHandle; while (curHandle != null) { curHandle = curHandle.getPrev(); if (curHandle != null && clazz.isInstance(curHandle.getInstruction())) { return clazz.cast(curHandle.getInstruction()); } } return null; }
if(invoke.getMethodName(cpg).equals("<init>") && invoke.getClassName(cpg).equals("java.lang.String") && invoke.getSignature(cpg).equals("(Ljava/lang/String;)V")) { return getConstantLDC(h.getPrev(), cpg, clazz);
@Override public InstructionHandle next() { if (!hasNext()) { throw new NoSuchElementException(); } InstructionHandle result = next; if(result == block.getFirstInstruction()) { do { Iterator<Edge> edgeIterator = cfg.incomingEdgeIterator(block); if(!edgeIterator.hasNext()) { break; } Edge edge = edgeIterator.next(); if(!edgeIterator.hasNext() && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE) { block = edge.getSource(); } else { break; } } while(block.isExceptionThrower()); } next = (block.isExceptionThrower() || result == block.getFirstInstruction()) ? null : next.getPrev(); return result; }
} else if ( "assertFalse".equals(methodName) && "(Z)V".equals(methodSig)) { SourceLineAnnotation lastLocation = bugAccumulator.getLastBugLocation(); InstructionHandle prevHandle = location.getHandle().getPrev(); if (lastLocation != null && prevHandle != null && lastLocation.getEndBytecode() == prevHandle.getPosition()){ bugAccumulator.forgetLastBug();
/** * @param handle instruction handle which loads the object for further GETFIELD/PUTFIELD operation * @return true if this object is known to be non-null */ private boolean isSafeFieldSource(InstructionHandle handle) { while(handle != null && handle.getInstruction().getOpcode() == Const.DUP) { // Some compilers generate DUP for field increment code like // ALOAD_0 / DUP / GETFIELD x / ICONST_1 / IADD / PUTFIELD x handle = handle.getPrev(); } if(handle == null) { return false; } Instruction inst = handle.getInstruction(); if(inst.getOpcode() == Const.ALOAD_0) { return true; } if(inst instanceof GETFIELD && ((GETFIELD)inst).getFieldName(cpg).startsWith("this$")) { return true; } return false; }
public Location getPreviousLocation(Location loc) { InstructionHandle handle = loc.getHandle(); BasicBlock basicBlock = loc.getBasicBlock(); if (basicBlock.getFirstInstruction().equals(handle)) { BasicBlock prevBlock = basicBlock; while (true) { prevBlock = getPredecessorWithEdgeType(prevBlock, EdgeTypes.FALL_THROUGH_EDGE); if (prevBlock == null) { return loc; } handle = prevBlock.getLastInstruction(); if (handle != null) { return new Location(handle, prevBlock); } } } else { handle = handle.getPrev(); return new Location(handle, basicBlock); } }
return !isSafeFieldSource(handle.getPrev()); for(InstructionHandle prev = handle.getPrev(); prev != null; prev = prev.getPrev()) { Instruction prevInst = prev.getInstruction(); if(prevInst instanceof BranchInstruction) { InstructionHandle prevPrev = prev.getPrev(); if(prevPrev != null && prevPrev.getInstruction() instanceof BranchInstruction) { continue;
InstructionHandle prevIns = firstIns.getPrev(); // prev in
INVOKESTATIC invoke = (INVOKESTATIC) inst; if ("javax.crypto.KeyGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) { String value = ByteCode.getConstantLDC(location.getHandle().getPrev(), cpg, String.class); if ("Blowfish".equals(value)) { createBlowfishKeyGen = true; n = ByteCode.getPushNumber(location.getHandle().getPrev());
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException{ JavaClass clazz = classContext.getJavaClass(); ConstantPoolGen cpg = classContext.getConstantPoolGen(); CFG cfg = classContext.getCFG(m); 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( "java.lang.StringBuilder".equals(invoke.getClassName(cpg)) && "append".equals(invoke.getMethodName(cpg))) { Instruction prev = loc.getHandle().getPrev().getInstruction(); if (prev instanceof LDC) { LDC ldc = (LDC)prev; Object value = ldc.getValue(cpg); if (value instanceof String) { String v = (String)value; if ("redirect:".equals(v)) { BugInstance bug = new BugInstance(this, SPRING_UNVALIDATED_REDIRECT_TYPE, Priorities.NORMAL_PRIORITY); bug.addClass(clazz).addMethod(clazz,m).addSourceLine(classContext,m,loc); reporter.reportBug(bug); } } } } } } }
InvokeInstruction invoke = (InvokeInstruction) inst; if ("setAttribute".equals(invoke.getMethodName(cpg))) { LDC propertyConst = ByteCode.getPrevInstruction(location.getHandle().getPrev(), LDC.class); LDC loadConst = ByteCode.getPrevInstruction(location.getHandle(), LDC.class); if (propertyConst != null && loadConst != null) { LDC propertyConst = ByteCode.getPrevInstruction(location.getHandle().getPrev(), LDC.class); ICONST loadConst = ByteCode.getPrevInstruction(location.getHandle(), ICONST.class); if (propertyConst != null && loadConst != null
public static LocalVariableAnnotation findLocalAnnotationFromValueNumber(Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame) { if (vnaFrame == null || vnaFrame.isBottom() || vnaFrame.isTop()) { return null; } LocalVariableAnnotation localAnnotation = null; for (int i = 0; i < vnaFrame.getNumLocals(); i++) { if (valueNumber.equals(vnaFrame.getValue(i))) { InstructionHandle handle = location.getHandle(); InstructionHandle prev = handle.getPrev(); if (prev == null) { continue; } int position1 = prev.getPosition(); int position2 = handle.getPosition(); localAnnotation = LocalVariableAnnotation.getLocalVariableAnnotation(method, i, position1, position2); if (localAnnotation != null) { return localAnnotation; } } } return null; }
Integer val = ByteCode.getConstantInt(handle.getPrev());
Integer booleanValue = ByteCode.getConstantInt(location.getHandle().getPrev()); if (booleanValue != null && booleanValue == 0) { escapeXmlSetToFalse = true;
/** * Get the dataflow fact representing the point just after given Location. * Note "after" is meant in the logical sense, so for backward analyses, * after means before the location in the control flow sense. * * @param location * the location * @return the fact at the point just after the location */ @Override public Fact getFactAfterLocation(Location location) throws DataflowAnalysisException { BasicBlock basicBlock = location.getBasicBlock(); InstructionHandle handle = location.getHandle(); if (handle == (isForwards() ? basicBlock.getLastInstruction() : basicBlock.getFirstInstruction())) { return getResultFact(basicBlock); } else { return getFactAtLocation(new Location(isForwards() ? handle.getNext() : handle.getPrev(), basicBlock)); } }
String value = ByteCode.getConstantLDC(location.getHandle().getPrev(),cpg,String.class); if (value == null) { JavaClass clz = classContext.getJavaClass();
InstructionHandle elseLastIns = elseFinishHandle.getPrev(); if (elseLastIns != null) { elseFinishPos = elseLastIns.getPosition();