/* goodG2B() - use goodsource and badsink */ private static void GoodG2B() { int count = CWE400_Uncontrolled_Resource_Consumption__Database_for_loop_61b.GoodG2BSource(); int i = 0; /* POTENTIAL FLAW: For loop using count as the loop variant and no validation */ for (i = 0; i < count; i++) { IO.WriteLine("Hello"); } }
public override void Bad() { int count = CWE400_Uncontrolled_Resource_Consumption__Database_for_loop_61b.BadSource(); int i = 0; /* POTENTIAL FLAW: For loop using count as the loop variant and no validation */ for (i = 0; i < count; i++) { IO.WriteLine("Hello"); } }
/* goodB2G() - use badsource and goodsink */ private static void GoodB2G() { int count = CWE400_Uncontrolled_Resource_Consumption__Database_for_loop_61b.GoodB2GSource(); int i = 0; /* FIX: Validate count before using it as the for loop variant */ if (count > 0 && count <= 20) { for (i = 0; i < count; i++) { IO.WriteLine("Hello"); } } }