/* goodG2B() - use goodsource and badsink */ private static void GoodG2B() { int data = CWE129_Improper_Validation_of_Array_Index__Connect_tcp_array_size_61b.GoodG2BSource(); int[] array = null; /* POTENTIAL FLAW: Verify that data is non-negative, but still allow it to be 0 */ if (data >= 0) { array = new int[data]; } else { IO.WriteLine("Array size is negative"); } /* do something with the array */ array[0] = 5; IO.WriteLine(array[0]); }
/* goodB2G() - use badsource and goodsink */ private static void GoodB2G() { int data = CWE129_Improper_Validation_of_Array_Index__Connect_tcp_array_size_61b.GoodB2GSource(); /* Need to ensure that the array is of size > 3 and < 101 due to the GoodSource and the large_fixed BadSource */ int[] array = null; /* FIX: Verify that data is non-negative AND greater than 0 */ if (data > 0) { array = new int[data]; } else { IO.WriteLine("Array size is negative"); } /* do something with the array */ array[0] = 5; IO.WriteLine(array[0]); }