/** * @param aInstruction * @param aPoolGen */ public GETFIELDReference( GETFIELD aInstruction, ConstantPoolGen aPoolGen) { super(aInstruction, aPoolGen); }
@Override public void visitGETFIELD(GETFIELD obj) { Taint.State state = taintConfig.getClassTaintState(obj.getSignature(cpg), Taint.State.UNKNOWN); Taint taint = new Taint(state); if (!state.equals(Taint.State.SAFE)){ taint.addLocation(getTaintLocation(), false); } if (FindSecBugsGlobalConfig.getInstance().isDebugTaintState()) { taint.setDebugInfo("." + obj.getFieldName(cpg)); } modelInstruction(obj, getNumWordsConsumed(obj), getNumWordsProduced(obj), taint); }
@Override public void visitGETFIELD(GETFIELD obj) { Type type = obj.getType(getCPG()); if (type.getSignature().equals(STRING_SIGNATURE)) { handleLoad(obj); } else { XField xf = XFactory.createXField(obj, cpg); if (xf.isFinal()) { FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary(); Item summary = fieldSummary.getSummary(xf); if (summary.isNull()) { consumeStack(obj); pushValue(TypeFrame.getNullType()); return; } String slashedClassName = ClassName.fromFieldSignature(type.getSignature()); if (slashedClassName != null) { String dottedClassName = ClassName.toDottedClassName(slashedClassName); if (DEFAULT_SUSPICIOUS_SET.contains(dottedClassName)) { type = new FinalConstant(dottedClassName, xf); consumeStack(obj); pushValue(type); return; } } } super.visitGETFIELD(obj); } }
@Override public void visitGETFIELD(GETFIELD obj) { XField xfield = Hierarchy.findXField(obj, getCPG()); if (xfield != null) { if (xfield.isVolatile()) getFrame().killAllLoads(); if (doRedundantLoadElimination()) { loadInstanceField(xfield, obj); return; } } handleNormalInstruction(obj); }
@Override public void visitGETFIELD(GETFIELD obj) { if (getNumWordsProduced(obj) != 1) { super.visitGETFIELD(obj); return; } if (checkForKnownValue(obj)) { return; } XField field = XFactory.createXField(obj, cpg); NullnessAnnotation annotation = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase() .getResolvedAnnotation(field, false); if (annotation == NullnessAnnotation.NONNULL) { modelNormalInstruction(obj, getNumWordsConsumed(obj), 0); produce(IsNullValue.nonNullValue()); } else if (annotation == NullnessAnnotation.CHECK_FOR_NULL) { modelNormalInstruction(obj, getNumWordsConsumed(obj), 0); produce(IsNullValue.nullOnSimplePathValue().markInformationAsComingFromFieldValue(field)); } else { super.visitGETFIELD(obj); } }
/** @see org.apache.bcel.generic.Visitor */ public void visitGETFIELD(GETFIELD aGETFIELD) { addFieldReference( new GETFIELDReference(aGETFIELD, mCurrentPoolGen)); }
byte[] counterAdaptClass(final InputStream is, final String name) throws Exception { JavaClass jc = new ClassParser(is, name + ".class").parse(); ClassGen cg = new ClassGen(jc); ConstantPoolGen cp = cg.getConstantPool(); if (!cg.isInterface()) { FieldGen fg = new FieldGen(ACC_PUBLIC, Type.getType("I"), "_counter", cp); cg.addField(fg.getField()); } Method[] ms = cg.getMethods(); for (int j = 0; j < ms.length; ++j) { MethodGen mg = new MethodGen(ms[j], cg.getClassName(), cp); if (!mg.getName().equals("<init>") && !mg.isStatic() && !mg.isAbstract() && !mg.isNative()) { if (mg.getInstructionList() != null) { InstructionList il = new InstructionList(); il.append(new ALOAD(0)); il.append(new ALOAD(0)); il.append(new GETFIELD(cp.addFieldref(name, "_counter", "I"))); il.append(new ICONST(1)); il.append(new IADD()); il.append(new PUTFIELD(cp.addFieldref(name, "_counter", "I"))); mg.getInstructionList().insert(il); mg.setMaxStack(Math.max(mg.getMaxStack(), 2)); boolean lv = ms[j].getLocalVariableTable() == null; boolean ln = ms[j].getLineNumberTable() == null; if (lv) { mg.removeLocalVariables(); } if (ln) { mg.removeLineNumbers(); } cg.replaceMethod(ms[j], mg.getMethod()); } } } return cg.getJavaClass().getBytes(); }
public boolean ignoreExceptionEdge(Edge edge, Lock resource, ConstantPoolGen cpg) { try { Location location = cfg.getExceptionThrowerLocation(edge); if (DEBUG) { System.out.println("Exception thrower location: " + location); } Instruction ins = location.getHandle().getInstruction(); if (ins instanceof GETFIELD) { GETFIELD insGetfield = (GETFIELD) ins; String fieldName = insGetfield.getFieldName(cpg); if (DEBUG) { System.out.println("Inspecting GETFIELD of " + fieldName + " at " + location); } // Ignore exceptions from getfield instructions where the // object reference is known not to be null if (fieldName.equals("lock")) return true; IsNullValueFrame frame = isNullDataflow.getFactAtLocation(location); if (!frame.isValid()) return false; IsNullValue receiver = frame.getInstance(ins, cpg); boolean notNull = receiver.isDefinitelyNotNull(); if (DEBUG && notNull) { System.out.println("Ignoring exception from non-null GETFIELD"); } return notNull; } else if (ins instanceof InvokeInstruction) { InvokeInstruction iins = (InvokeInstruction) ins; String methodName = iins.getMethodName(cpg); // System.out.println("Method " + methodName); if (methodName.startsWith("access$")) return true; if (methodName.equals("readLock") || methodName.equals("writeLock")) return true; if (methodName.equals("lock") || methodName.equals("unlock")) return true; } if (DEBUG) { System.out.println("FOUND Exception thrower at: " + location); } } catch (DataflowAnalysisException e) { AnalysisContext.logError("Error while looking for exception edge", e); } return false; }
/** * Is the given instruction a read of a field? * * @param ins * the Instruction to check * @param cpg * ConstantPoolGen of the method containing the instruction * @return the Field if the instruction is a read of a field, null otherwise */ public static FieldAnnotation isRead(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof GETFIELD || ins instanceof GETSTATIC) { FieldInstruction fins = (FieldInstruction) ins; String className = fins.getClassName(cpg); return new FieldAnnotation(className, fins.getName(cpg), fins.getSignature(cpg), fins instanceof GETSTATIC); } else return null; }