text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE606_Unchecked_Loop_Condition__char_fromConsole_53d.c
  Label Definition File: CWE606_Unchecked_Loop_Condition.label.xml
  Template File: sources-sinks-53d.tmpl.c
  */
  /*
   * @description
   * CWE: 606 Unchecked Input For Loop Condition
   * BadSource: fromConsole Read input from the console
   * GoodSource: Input a number less than MAX_LOOP
   * Sinks:
   *    GoodSink: Use data as the for loop variant after checking to see if it is less than MAX_LOOP
   *    BadSink : Use data as the for loop variant without checking its size
   * Flow Variant: 53 Data flow: data passed as an argument from one function through two others to a fourth; all four functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #define MAX_LOOP 10000
  
  #ifndef OMITBAD
  
  void CWE606_Unchecked_Loop_Condition__char_fromConsole_53d_bad_sink(char * data)
  {
      {
          int i, n, v;
          if (sscanf(data, "%d", &n) == 1)
          {
              /* POTENTIAL FLAW: user-supplied value 'n' could lead to very large loop iteration */
              v = 0;
              for (i = 0; i < n; i++)
              {
                  /* INCIDENTAL: CWE 561: Dead Code - non-avoidable if n <= 0 */
                  v++; /* avoid a dead/empty code block issue */
              }
              printIntLine(v);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE606_Unchecked_Loop_Condition__char_fromConsole_53d_goodG2B_sink(char * data)
  {
      {
          int i, n, v;
          if (sscanf(data, "%d", &n) == 1)
          {
              /* POTENTIAL FLAW: user-supplied value 'n' could lead to very large loop iteration */
              v = 0;
              for (i = 0; i < n; i++)
              {
                  /* INCIDENTAL: CWE 561: Dead Code - non-avoidable if n <= 0 */
                  v++; /* avoid a dead/empty code block issue */
              }
              printIntLine(v);
          }
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE606_Unchecked_Loop_Condition__char_fromConsole_53d_goodB2G_sink(char * data)
  {
      {
          int i, n, v;
          if (sscanf(data, "%d", &n) == 1)
          {
              /* FIX: limit loop iteration counts */
              if (n < MAX_LOOP)
              {
                  v = 0;
                  for (i = 0; i < n; i++)
                  {
                      /* INCIDENTAL: CWE 561: Dead Code - non-avoidable if n <= 0 */
                      v++; /* avoid a dead/empty code block issue */
                  }
                  printIntLine(v);
              }
          }
      }
  }
  
  #endif /* OMITGOOD */
  