/* goodG2B() - use goodsource and badsink */ public static void GoodG2BSink(CWE129_Improper_Validation_of_Array_Index__NetClient_array_write_no_check_67a.Container dataContainer) { int data = dataContainer.containerOne; /* Need to ensure that the array is of size > 3 and < 101 due to the GoodSource and the large_fixed BadSource */ int[] array = { 0, 1, 2, 3, 4 }; /* POTENTIAL FLAW: Attempt to write to array at location data, which may be outside the array bounds */ array[data] = 42; /* Skip reading back data from array since that may be another out of bounds operation */ }
/* goodB2G() - use badsource and goodsink */ public static void GoodB2GSink(CWE129_Improper_Validation_of_Array_Index__NetClient_array_write_no_check_67a.Container dataContainer) { int data = dataContainer.containerOne; /* Need to ensure that the array is of size > 3 and < 101 due to the GoodSource and the large_fixed BadSource */ int[] array = { 0, 1, 2, 3, 4 }; /* FIX: Verify index before writing to array at location data */ if (data >= 0 && data < array.Length) { array[data] = 42; } else { IO.WriteLine("Array index out of bounds"); } }