/* goodG2B() - use goodsource and badsink */ private static void GoodG2B() { int data = CWE190_Integer_Overflow__int_max_square_61b.GoodG2BSource(); /* POTENTIAL FLAW: if (data*data) > int.MaxValue, this will overflow */ int result = (int)(data * data); IO.WriteLine("result: " + result); }
public override void Bad() { int data = CWE190_Integer_Overflow__int_max_square_61b.BadSource(); /* POTENTIAL FLAW: if (data*data) > int.MaxValue, this will overflow */ int result = (int)(data * data); IO.WriteLine("result: " + result); }
/* goodB2G() - use badsource and goodsink */ private static void GoodB2G() { int data = CWE190_Integer_Overflow__int_max_square_61b.GoodB2GSource(); /* FIX: Add a check to prevent an overflow from occurring */ if (Math.Abs((long)data) <= (long)Math.Sqrt(int.MaxValue)) { int result = (int)(data * data); IO.WriteLine("result: " + result); } else { IO.WriteLine("data value is too large to perform squaring."); } }