/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE191_Integer_Underflow__short_min_predec_61b.java Label Definition File: CWE191_Integer_Underflow.label.xml Template File: sources-sinks-61b.tmpl.java */ /* * @description * CWE: 191 Integer Underflow * BadSource: min Set data to the max value for short * GoodSource: A hardcoded non-zero, non-min, non-max, even number * Sinks: decrement * GoodSink: Ensure there will not be an underflow before decrementing data * BadSink : Decrement data, which can cause an Underflow * Flow Variant: 61 Data flow: data returned from one method to another in different classes in the same package * * */ package testcases.CWE191_Integer_Underflow.s05; import testcasesupport.*; public class CWE191_Integer_Underflow__short_min_predec_61b { public short badSource() throws Throwable { short data; /* POTENTIAL FLAW: Use the maximum size of the data type */ data = Short.MIN_VALUE; return data; } /* goodG2B() - use goodsource and badsink */ public short goodG2BSource() throws Throwable { short data; /* FIX: Use a hardcoded number that won't cause underflow, overflow, divide by zero, or loss-of-precision issues */ data = 2; return data; } /* goodB2G() - use badsource and goodsink */ public short goodB2GSource() throws Throwable { short data; /* POTENTIAL FLAW: Use the maximum size of the data type */ data = Short.MIN_VALUE; return data; } }