public boolean isServletWriter() { if (getSpecialKind() == Item.SERVLET_OUTPUT) { return true; } if ("Ljavax/servlet/ServletOutputStream;".equals(getSignature())) { return true; } XMethod writingToSource = getReturnValueOf(); return writingToSource != null && "javax.servlet.http.HttpServletResponse".equals(writingToSource.getClassName()) && ("getWriter".equals(writingToSource.getName()) || "getOutputStream".equals(writingToSource.getName())); }
if ("java/io/ObjectOutputStream".equals(calledClassName) && Const.CONSTRUCTOR_NAME.equals(calledMethodName) && "(Ljava/io/OutputStream;)V".equals(calledMethodSig) && stack.getStackItem(0).getSpecialKind() == OpcodeStack.Item.FILE_OPENED_IN_APPEND_MODE) { bugReporter.reportBug(new BugInstance(this, "IO_APPENDING_TO_OBJECT_OUTPUT_STREAM", Priorities.HIGH_PRIORITY) .addClassAndMethod(this).addSourceLine(this));
if (i1.getSpecialKind() == TYPE_ONLY && i2.getSpecialKind() != TYPE_ONLY) { return i2; } else if (i2.getSpecialKind() == TYPE_ONLY && i1.getSpecialKind() != TYPE_ONLY) { return i1;
/** The result of applying Math.abs to a checkForIntegerMinValue() value */ public boolean mightRarelyBeNegative() { return !isNonNegative() && (getSpecialKind() == Item.MATH_ABS_OF_RANDOM || getSpecialKind() == Item.MATH_ABS_OF_HASHCODE); }
if (seen == Const.IFLT && stack.getStackDepth() > 0 && stack.getStackItem(0).getSpecialKind() == OpcodeStack.Item.SIGNED_BYTE) { sawCheckForNonNegativeSignedByte = getPC(); ) { OpcodeStack.Item item0 = stack.getStackItem(0); int special = item0.getSpecialKind(); if (special == OpcodeStack.Item.RANDOM_INT) { pendingAbsoluteValueBug = new BugInstance(this, "RV_ABSOLUTE_VALUE_OF_RANDOM_INT", HIGH_PRIORITY) if (stackLoc >= 0) { OpcodeStack.Item tos = stack.getStackItem(stackLoc); switch (tos.getSpecialKind()) { case OpcodeStack.Item.HASHCODE_INT_REMAINDER: accumulator.accumulateBug(new BugInstance(this, "RV_REM_OF_HASHCODE", HIGH_PRIORITY).addClassAndMethod(this), if (item0.getSpecialKind() == OpcodeStack.Item.SIGNED_BYTE) { int[] switchLabels = getSwitchLabels(); int[] switchOffsets = getSwitchOffsets(); if (item0.getSpecialKind() == OpcodeStack.Item.SIGNED_BYTE && constant1 instanceof Number) { int v1 = ((Number) constant1).intValue(); if (v1 <= -129 || v1 >= 128 || v1 == 127 && !(seen2 == Const.IF_ICMPEQ || seen2 == Const.IF_ICMPNE } else if (item0.getSpecialKind() == OpcodeStack.Item.NON_NEGATIVE && constant1 instanceof Number) { int v1 = ((Number) constant1).intValue(); if (v1 < 0) { case Const.IFGE: case Const.IFLT:
int specialKind = topItem.getSpecialKind(); for (Item item : stack) { if (item != null && item.getSpecialKind() == specialKind) { item.setSpecialKind(Item.NOT_SPECIAL); if (item != null && item.getSpecialKind() == specialKind) { item.setSpecialKind(Item.NOT_SPECIAL); Item newValue = new Item(it, "J"); int specialKind = it.getSpecialKind(); case Const.F2I: it = pop(); int oldSpecialKind = it.getSpecialKind(); it = new Item(it, "I");
if (index.getSpecialKind() == Item.AVERAGE_COMPUTED_USING_DIVISION) { SourceLineAnnotation where; if (index.getPC() >= 0) { if (seen == Const.IREM) { OpcodeStack.Item item = stack.getStackItem(1); if (!item.isNonNegative() && item.getSpecialKind() != OpcodeStack.Item.MATH_ABS) { badlyComputingOddState++; } else { value = rhs; if (constant instanceof Number && (seen == Const.LAND || value.getSpecialKind() == OpcodeStack.Item.RESULT_OF_L2I)) { long constantValue = ((Number) constant).longValue(); if ((constantValue == 0xEFFFFFFFL || constantValue == 0xEFFFFFFFFFFFFFFFL || seen == Const.IAND
&& "(Ljava/io/OutputStream;)V".equals(signature)) { if (getStackItem(0).getSpecialKind() == Item.FILE_OPENED_IN_APPEND_MODE && "Ljava/io/BufferedOutputStream;".equals(getStackItem(2).signature)) { && Subtypes2.instanceOf(ClassName.toDottedClassName(clsName), "java.util.Collection")) { Item i = new Item(pop()); if (i.getSpecialKind() == Item.NOT_SPECIAL) { i.setSpecialKind(Item.NON_NEGATIVE); if (i.getSpecialKind() == Item.HASHCODE_INT) { i.setSpecialKind(Item.MATH_ABS_OF_HASHCODE); } else if (i.getSpecialKind() == Item.RANDOM_INT) { i.setSpecialKind(Item.MATH_ABS_OF_RANDOM); } else {
newValue.setSpecialKind(Item.NON_NEGATIVE); } else if (seen == Const.IAND && lhs.getSpecialKind() == Item.ZERO_MEANS_NULL) { newValue.setSpecialKind(Item.ZERO_MEANS_NULL); newValue.setPC(lhs.getPC()); } else if (seen == Const.IAND && rhs.getSpecialKind() == Item.ZERO_MEANS_NULL) { newValue.setSpecialKind(Item.ZERO_MEANS_NULL); newValue.setPC(rhs.getPC()); } else if (seen == Const.IOR && lhs.getSpecialKind() == Item.NONZERO_MEANS_NULL) { newValue.setSpecialKind(Item.NONZERO_MEANS_NULL); newValue.setPC(lhs.getPC()); } else if (seen == Const.IOR && rhs.getSpecialKind() == Item.NONZERO_MEANS_NULL) { newValue.setSpecialKind(Item.NONZERO_MEANS_NULL); newValue.setPC(rhs.getPC()); if (lhs.getSpecialKind() == Item.INTEGER_SUM && rhs.getConstant() != null) { int rhsValue = constantToInt(rhs); if (seen == Const.IDIV && rhsValue == 2 || seen == Const.ISHR && rhsValue == 1) { if (seen == Const.IADD && newValue.getSpecialKind() == Item.NOT_SPECIAL && lhs.getConstant() == null && rhs.getConstant() == null) { newValue.setSpecialKind(Item.INTEGER_SUM); if (seen == Const.IREM && lhs.getSpecialKind() == Item.HASHCODE_INT) { newValue.setSpecialKind(Item.HASHCODE_INT_REMAINDER); if (seen == Const.IREM && lhs.getSpecialKind() == Item.RANDOM_INT) { newValue.setSpecialKind(Item.RANDOM_INT_REMAINDER);
break; if (first.getSpecialKind() == OpcodeStack.Item.NASTY_FLOAT_MATH && !isZero(n2) || second.getSpecialKind() == OpcodeStack.Item.NASTY_FLOAT_MATH && !isZero(n1) || first.getSpecialKind() == OpcodeStack.Item.FLOAT_MATH && !okValueToCompareAgainst(n2) || second.getSpecialKind() == OpcodeStack.Item.FLOAT_MATH && !okValueToCompareAgainst(n1)) { if (priority != HIGH_PRIORITY) { found.clear();
@Override public void sawOpcode(int seen) { if (seen == Const.SIPUSH) { lastConstantForSIPUSH = getIntConstant(); } if (seen == Const.INVOKEINTERFACE || seen == Const.INVOKEVIRTUAL || seen == Const.INVOKESPECIAL || seen == Const.INVOKESTATIC) { String signature = getSigConstantOperand(); int numberArguments = PreorderVisitor.getNumberArguments(signature); for (int i = 0; i < numberArguments; i++) { Item item = stack.getStackItem(numberArguments - 1 - i); if (item.getSpecialKind() == OpcodeStack.Item.RESULT_OF_I2L) { ParameterProperty property = database.getProperty(getMethodDescriptorOperand()); if (property != null && property.hasProperty(i)) { int priority = NORMAL_PRIORITY; if (getPrevOpcode(1) == Const.I2L && getPrevOpcode(2) == Const.IMUL && getPrevOpcode(3) == Const.SIPUSH && lastConstantForSIPUSH == 1000) { priority = HIGH_PRIORITY; } else if (getPrevOpcode(1) == Const.I2L && getPrevOpcode(2) == Const.IMUL && getPrevOpcode(4) == Const.SIPUSH && lastConstantForSIPUSH == 1000) { priority = HIGH_PRIORITY; } BugInstance bug = new BugInstance(this, "ICAST_INT_2_LONG_AS_INSTANT", priority).addClassAndMethod(this) .addCalledMethod(this).addValueSource(item, this).addSourceLine(this); bugReporter.reportBug(bug); } } } } }
if (it.getSpecialKind() == OpcodeStack.Item.FILE_SEPARATOR_STRING && (flags & Pattern.LITERAL) == 0) { bugReporter.reportBug(new BugInstance(this, "RE_CANT_USE_FILE_SEPARATOR_AS_REGULAR_EXPRESSION", HIGH_PRIORITY) .addClassAndMethod(this).addCalledMethod(this).addSourceLine(this));
private void checkForCompatibleLongComparison(OpcodeStack.Item left, OpcodeStack.Item right) { if (left.getSpecialKind() == Item.RESULT_OF_I2L && right.getConstant() != null) { long value = ((Number) right.getConstant()).longValue(); if ( (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE)) { int priority = Priorities.HIGH_PRIORITY; if (value == Integer.MAX_VALUE+1L || value == Integer.MIN_VALUE-1L) { priority = Priorities.NORMAL_PRIORITY; } String stringValue = IntAnnotation.getShortInteger(value)+"L"; if (value == 0xffffffffL) { stringValue = "0xffffffffL"; } else if (value == 0x80000000L) { stringValue = "0x80000000L"; } accumulator.accumulateBug(new BugInstance(this, "INT_BAD_COMPARISON_WITH_INT_VALUE", priority ).addClassAndMethod(this) .addString(stringValue).describe(StringAnnotation.STRING_NONSTRING_CONSTANT_ROLE) .addValueSource(left, this) , this); } } }
public boolean isServletParameterTainted() { return getSpecialKind() == Item.SERVLET_REQUEST_TAINTED; }
private boolean nullGuaranteesBranch(int seen, OpcodeStack.Item item) { return item.getSpecialKind() == OpcodeStack.Item.ZERO_MEANS_NULL && seen == Const.IAND || item.getSpecialKind() == OpcodeStack.Item.NONZERO_MEANS_NULL && seen == Const.IOR; }
public @SpecialKind int getSpecialKindForRemainder() { switch (getSpecialKind()) { case Item.HASHCODE_INT: return Item.HASHCODE_INT_REMAINDER; case Item.RANDOM_INT: return Item.RANDOM_INT_REMAINDER; default: return Item.NOT_SPECIAL; } }
/** Value could be Integer.MIN_VALUE */ public boolean checkForIntegerMinValue() { return !isNonNegative() && (getSpecialKind() == Item.RANDOM_INT || getSpecialKind() == Item.HASHCODE_INT); }
/** The result of applying Math.abs to a checkForIntegerMinValue() value */ public boolean mightRarelyBeNegative() { return !isNonNegative() && (getSpecialKind() == Item.MATH_ABS_OF_RANDOM || getSpecialKind() == Item.MATH_ABS_OF_HASHCODE); }
public @SpecialKind int getSpecialKindForAbs() { switch (getSpecialKind()) { case Item.HASHCODE_INT: return Item.MATH_ABS_OF_HASHCODE; case Item.RANDOM_INT: return Item.MATH_ABS_OF_RANDOM; default: return Item.MATH_ABS; } }
public boolean valueCouldBeNegative() { return !isNonNegative() && (getSpecialKind() == Item.RANDOM_INT || getSpecialKind() == Item.SIGNED_BYTE || getSpecialKind() == Item.HASHCODE_INT || getSpecialKind() == Item.RANDOM_INT_REMAINDER || getSpecialKind() == Item.HASHCODE_INT_REMAINDER || getSpecialKind() == Item.MATH_ABS_OF_RANDOM || getSpecialKind() == Item.MATH_ABS_OF_HASHCODE); }