public static XField createXField(FieldAnnotation f) { return createXField(f.getClassName(), f.getFieldName(), f.getFieldSignature(), f.isStatic()); }
private void analyzeField(Field field, JavaClass javaClass) { for (AnnotationEntry annotation : field.getAnnotationEntries()) { if (ANNOTATION_TYPES.contains(annotation.getAnnotationType()) || annotation.getAnnotationType().contains("JsonTypeInfo")) { for (ElementValuePair elementValuePair : annotation.getElementValuePairs()) { if ("use".equals((elementValuePair.getNameString())) && VULNERABLE_USE_NAMES.contains(elementValuePair.getValue().stringifyValue())) { bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY) .addClass(javaClass) .addString(javaClass.getClassName() + " on field " + field.getName() + " of type " + field.getType() + " annotated with " + annotation.toShortString()) .addField(FieldAnnotation.fromBCELField(javaClass, field)) .addString("") ); } } } } }
static FieldAnnotation obfuscate(FieldAnnotation m) { FieldAnnotation result = new FieldAnnotation(hashClass(m.getClassName()), hashData(m.getFieldName()), hashSignature(m.getFieldSignature()), m.isStatic()); result.setDescription(m.getDescription()); return result; }
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getFieldName()).addAttribute("signature", getFieldSignature()); if (fieldSourceSig != null) { attributeList.addAttribute("sourceSignature", fieldSourceSig); } attributeList.addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } xmlOutput.openTag(ELEMENT_NAME, attributeList); getSourceLines().writeXML(xmlOutput, addMessages, false); if (addMessages) { xmlOutput.openTag(BugAnnotation.MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(BugAnnotation.MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
/** * Add a field annotation. * * @param className * name of the class containing the field * @param fieldName * the name of the field * @param fieldSig * type signature of the field * @param accessFlags * access flags for the field * @return this object */ @Nonnull public BugInstance addField(String className, String fieldName, String fieldSig, int accessFlags) { addField(new FieldAnnotation(className, fieldName, fieldSig, accessFlags)); return this; }
FieldAnnotation field = FieldAnnotation.fromReferencedField(dbc); Item i = new Item(dbc.getSigConstantOperand(), field, Integer.MAX_VALUE); if ("separator".equals(field.getFieldName()) && "java.io.File".equals(field.getClassName())) { i.setSpecialKind(Item.FILE_SEPARATOR_STRING); Item valueLoaded = new Item(dbc.getSigConstantOperand(), FieldAnnotation.fromReferencedField(dbc), reg); valueLoaded.setPC(dbc.getPC()); push(valueLoaded);
@Override public boolean match(BugInstance bugInstance) { FieldAnnotation fieldAnnotation = null; if (role == null || "".equals(role)) { fieldAnnotation = bugInstance.getPrimaryField(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof FieldAnnotation && role.equals(a.getDescription())) { fieldAnnotation = (FieldAnnotation) a; break; } } } if (fieldAnnotation == null) { return false; } if (!name.match(fieldAnnotation.getFieldName())) { return false; } if (signature != null && !signature.match(fieldAnnotation.getFieldSignature())) { return false; } return true; }
/** * implements the visitor to find collection fields * * @param obj * the context object of the currently parse field */ @Override public void visitField(Field obj) { if (obj.isPrivate()) { String signature = obj.getSignature(); if (signature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX)) { try { JavaClass cls = Repository.lookupClass(SignatureUtils.stripSignature(signature)); if (cls.implementationOf(collectionClass) || cls.implementationOf(mapClass)) { FieldAnnotation fa = FieldAnnotation.fromVisitedField(this); collectionFields.put(fa.getFieldName(), new FieldInfo(fa)); } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); } } } }
return false; criteriaMatches &= fieldAnn.getFieldName().equals(fieldName);
@Nonnull public BugInstance addField(PreorderVisitor visitor) { FieldAnnotation fieldAnnotation = FieldAnnotation.fromVisitedField(visitor); return addField(fieldAnnotation); }
/** * Add a field annotation for the field which has just been accessed by the * method currently being visited by given visitor. Assumes that a * getfield/putfield or getstatic/putstatic has just been seen. * * @param visitor * the DismantleBytecode object * @return this object */ @Nonnull public BugInstance addReferencedField(DismantleBytecode visitor) { FieldAnnotation f = FieldAnnotation.fromReferencedField(visitor); addField(f); return this; }
Field maskingField = classFields.get(fieldName); String mClassName = getDottedClassName(); FieldAnnotation fa = new FieldAnnotation(mClassName, maskingField.getName(), maskingField.getSignature(), maskingField.isStatic()); int priority = NORMAL_PRIORITY; FieldAnnotation maskedFieldAnnotation = FieldAnnotation.fromFieldDescriptor(fld.getFieldDescriptor()); BugInstance bug = new BugInstance(this, "MF_CLASS_MASKS_FIELD", priority).addClass(this).addField(fa) .describe("FIELD_MASKING").addField(maskedFieldAnnotation).describe("FIELD_MASKED");
FieldAnnotation f = FieldAnnotation.fromReferencedField(this); String sig = f.getFieldSignature(); if (sig.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX)) { sig = SignatureUtils.trimSignature(sig);
case 0: if (seen == Const.GETFIELD || seen == Const.GETSTATIC) { syncField = FieldAnnotation.fromReferencedField(this); currState = 1; case 4: if (seen == Const.GETFIELD || seen == Const.GETSTATIC) { gottenField = FieldAnnotation.fromReferencedField(this); currState = 5; } else { if ((seen == Const.IFNONNULL || seen == Const.IFNULL) && gottenField.equals(syncField)) { BugInstance bug = new BugInstance(this, "NP_SYNC_AND_NULL_CHECK_FIELD", NORMAL_PRIORITY).addClass(this) .addMethod(this).addField(syncField).addSourceLine(this);
/** * Add a field annotation for a FieldDescriptor. * * @param fieldDescriptor * the FieldDescriptor * @return this object */ @Nonnull public BugInstance addField(FieldDescriptor fieldDescriptor) { FieldAnnotation fieldAnnotation = FieldAnnotation.fromFieldDescriptor(fieldDescriptor); add(fieldAnnotation); return this; }
private int compareFieldsAllowingNull(FieldAnnotation lhs, FieldAnnotation rhs) { if (lhs == null || rhs == null) { return compareNullElements(lhs, rhs); } lhs = convertField(lhs); rhs = convertField(rhs); if (DEBUG) { System.err.println("Compare fields: " + lhs + " and " + rhs); } return lhs.compareTo(rhs); }
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getFieldName()).addAttribute("signature", getFieldSignature()); if (fieldSourceSig != null) { attributeList.addAttribute("sourceSignature", fieldSourceSig); } attributeList.addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } xmlOutput.openTag(ELEMENT_NAME, attributeList); getSourceLines().writeXML(xmlOutput, addMessages, false); if (addMessages) { xmlOutput.openTag(BugAnnotation.MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(BugAnnotation.MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
/** * Add a field annotation. * * @param className * name of the class containing the field * @param fieldName * the name of the field * @param fieldSig * type signature of the field * @param isStatic * whether or not the field is static * @return this object */ @Nonnull public BugInstance addField(String className, String fieldName, String fieldSig, boolean isStatic) { addField(new FieldAnnotation(className, fieldName, fieldSig, isStatic)); return this; }
FieldAnnotation field = FieldAnnotation.fromReferencedField(dbc); Item i = new Item(dbc.getSigConstantOperand(), field, Integer.MAX_VALUE); if ("separator".equals(field.getFieldName()) && "java.io.File".equals(field.getClassName())) { i.setSpecialKind(Item.FILE_SEPARATOR_STRING); Item valueLoaded = new Item(dbc.getSigConstantOperand(), FieldAnnotation.fromReferencedField(dbc), reg); valueLoaded.setPC(dbc.getPC()); push(valueLoaded);
@Override public boolean match(BugInstance bugInstance) { FieldAnnotation fieldAnnotation = null; if (role == null || "".equals(role)) { fieldAnnotation = bugInstance.getPrimaryField(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof FieldAnnotation && role.equals(a.getDescription())) { fieldAnnotation = (FieldAnnotation) a; break; } } } if (fieldAnnotation == null) { return false; } if (!name.match(fieldAnnotation.getFieldName())) { return false; } if (signature != null && !signature.match(fieldAnnotation.getFieldSignature())) { return false; } return true; }