/* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    int count;

    count = Integer.MIN_VALUE; /* Initialize count */

    /* get environment variable ADD */
    /* POTENTIAL FLAW: Read count from an environment variable */
    {
      String stringNumber = System.getenv("ADD");
      if (stringNumber != null) // avoid NPD incidental warnings
      {
        try {
          count = Integer.parseInt(stringNumber.trim());
        } catch (NumberFormatException exceptNumberFormat) {
          IO.logger.log(
              Level.WARNING,
              "Number format exception parsing count from string",
              exceptNumberFormat);
        }
      }
    }

    Container countContainer = new Container();
    countContainer.containerOne = count;
    (new CWE400_Resource_Exhaustion__sleep_Environment_67b()).goodB2GSink(countContainer);
  }
  public void bad() throws Throwable {
    int data;

    /* POTENTIAL FLAW: Set data to a random value */
    data = (new SecureRandom()).nextInt();

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE789_Uncontrolled_Mem_Alloc__random_HashSet_67b()).badSink(dataContainer);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    int data;

    /* FIX: Use a hardcoded number that won't cause underflow, overflow, divide by zero, or loss-of-precision issues */
    data = 2;

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE789_Uncontrolled_Mem_Alloc__random_HashSet_67b()).goodG2BSink(dataContainer);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    String data;

    /* FIX: Set data to a fixed, non-null String */
    data = "CWE690";

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE690_NULL_Deref_From_Return__System_getProperty_trim_67b()).goodG2BSink(dataContainer);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    String data;

    /* POTENTIAL FLAW: data may be set to null */
    data = System.getProperty("CWE690");

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE690_NULL_Deref_From_Return__System_getProperty_trim_67b()).goodB2GSink(dataContainer);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    int data;

    /* FIX: Use a hardcoded number that won't cause underflow, overflow, divide by zero, or loss-of-precision issues */
    data = 2;

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE190_Integer_Overflow__int_random_square_67b()).goodG2BSink(dataContainer);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    int data;

    /* POTENTIAL FLAW: Set data to a random value */
    data = (new SecureRandom()).nextInt();

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE190_Integer_Overflow__int_random_square_67b()).goodB2GSink(dataContainer);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    int data;

    /* POTENTIAL FLAW: Use the maximum value for this type */
    data = Integer.MAX_VALUE;

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE190_Integer_Overflow__int_max_add_67b()).goodB2GSink(dataContainer);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    int count;

    /* FIX: Use a hardcoded number that won't cause underflow, overflow, divide by zero, or loss-of-precision issues */
    count = 2;

    Container countContainer = new Container();
    countContainer.containerOne = count;
    (new CWE400_Resource_Exhaustion__sleep_Environment_67b()).goodG2BSink(countContainer);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    int data;

    /* FIX: Use a hardcoded number that won't cause underflow, overflow, divide by zero, or loss-of-precision issues */
    data = 2;

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE129_Improper_Validation_of_Array_Index__File_array_read_no_check_67b())
        .goodG2BSink(dataContainer);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    String data;

    /* FIX: Use a hardcoded string */
    data = "foo";

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE15_External_Control_of_System_or_Configuration_Setting__console_readLine_67b())
        .goodG2BSink(dataContainer);
  }
  public void bad() throws Throwable {
    String data;

    Logger log_bad = Logger.getLogger("local-logger");

    /* get environment variable ADD */
    data = System.getenv("ADD");

    Container data_container = new Container();
    data_container.a = data;
    (new CWE617_Reachable_Assertion__Environment_67b()).bad_sink(data_container);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    String data;

    java.util.logging.Logger log_good = java.util.logging.Logger.getLogger("local-logger");

    /* FIX: Use a hardcoded string */
    data = "foo";

    Container data_container = new Container();
    data_container.a = data;
    (new CWE617_Reachable_Assertion__Environment_67b()).goodG2B_sink(data_container);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    String data;

    java.util.logging.Logger log_good = java.util.logging.Logger.getLogger("local-logger");

    /* FIX: Use a hardcoded string */
    data = "foo";

    Container data_container = new Container();
    data_container.a = data;
    (new CWE643_Unsafe_Treatment_of_XPath_Input__URLConnection_67b()).goodG2B_sink(data_container);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    String data;

    java.util.logging.Logger log_good = java.util.logging.Logger.getLogger("local-logger");

    /* FIX: Use a hardcoded string */
    data = "foo";

    Container data_container = new Container();
    data_container.a = data;
    (new CWE113_HTTP_Response_Splitting__URLConnection_sendRedirectServlet_67b())
        .goodG2B_sink(data_container, request, response);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    int data;

    java.util.logging.Logger log_good = java.util.logging.Logger.getLogger("local-logger");

    /* FIX: Use a hardcoded number that won't cause underflow, overflow,
    divide by zero, or loss-of-precision issues */
    data = 2;

    Container data_container = new Container();
    data_container.a = data;
    (new CWE191_Integer_Underflow__fromFile_multiply_67b()).goodG2B_sink(data_container);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    byte data;

    /* POTENTIAL FLAW: Use a random value */
    data =
        (byte)
            ((new java.security.SecureRandom()).nextInt(1 + Byte.MAX_VALUE - Byte.MIN_VALUE)
                + Byte.MIN_VALUE);

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE190_Integer_Overflow__byte_rand_add_67b()).goodB2GSink(dataContainer);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    String data;

    java.util.logging.Logger log_good = java.util.logging.Logger.getLogger("local-logger");

    /* FIX: Use a hardcoded string */
    data = "foo";

    Container data_container = new Container();
    data_container.a = data;
    (new CWE80_XSS__Servlet_getQueryStringServlet_67b())
        .goodG2B_sink(data_container, request, response);
  }
  /* goodG2B() - use goodsource and badsink */
  private void goodG2B() throws Throwable {
    int data;

    java.util.logging.Logger log_good = java.util.logging.Logger.getLogger("local-logger");

    /* FIX: Use a hardcoded number that won't cause underflow, overflow,
    divide by zero, or loss-of-precision issues */
    data = 2;

    Container data_container = new Container();
    data_container.a = data;
    (new CWE369_Divide_By_Zero__PropertiesFile_divide_67b()).goodG2B_sink(data_container);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    short data;

    /* POTENTIAL FLAW: Use a random value */
    data =
        (short)
            ((new java.security.SecureRandom()).nextInt(1 + Short.MAX_VALUE - Short.MIN_VALUE)
                + Short.MIN_VALUE);

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE191_Integer_Underflow__short_rand_multiply_67b()).goodB2GSink(dataContainer);
  }
  public void bad() throws Throwable {
    int data;

    Logger log_bad = Logger.getLogger("local-logger");

    /* init data */
    data = -1;

    File f = new File("C:\\name.txt");
    BufferedReader buffread = null;
    FileReader fread = null;
    try {
      /* read string from file into data */
      char[] readIn = new char[(new Long(f.length())).intValue()];
      fread = new FileReader(f);
      buffread = new BufferedReader(fread);

      String s_data =
          buffread.readLine(); // This will be reading the first "line" of the file, which
      // could be very long if there are little or no newlines in the file\
      data = Integer.parseInt(s_data.trim());
    } catch (IOException ioe) {
      log_bad.warning("Error with stream reading");
    } catch (NumberFormatException nfe) {
      log_bad.warning("Error with number parsing");
    } finally {
      /* clean up stream reading objects */
      try {
        if (buffread != null) {
          buffread.close();
        }
      } catch (IOException ioe) {
        log_bad.warning("Error closing buffread");
      } finally {
        try {
          if (fread != null) {
            fread.close();
          }
        } catch (IOException ioe) {
          log_bad.warning("Error closing fread");
        }
      }
    }

    Container data_container = new Container();
    data_container.a = data;
    (new CWE191_Integer_Underflow__fromFile_multiply_67b()).bad_sink(data_container);
  }
  public void bad() throws Throwable {
    String data;

    data = ""; /* Initialize data */

    {
      InputStreamReader readerInputStream = null;
      BufferedReader readerBuffered = null;

      /* read user input from console with readLine */
      try {
        readerInputStream = new InputStreamReader(System.in, "UTF-8");
        readerBuffered = new BufferedReader(readerInputStream);

        /* POTENTIAL FLAW: Read data from the console using readLine */
        data = readerBuffered.readLine();
      } catch (IOException exceptIO) {
        IO.logger.log(Level.WARNING, "Error with stream reading", exceptIO);
      } finally {
        try {
          if (readerBuffered != null) {
            readerBuffered.close();
          }
        } catch (IOException exceptIO) {
          IO.logger.log(Level.WARNING, "Error closing BufferedReader", exceptIO);
        }

        try {
          if (readerInputStream != null) {
            readerInputStream.close();
          }
        } catch (IOException exceptIO) {
          IO.logger.log(Level.WARNING, "Error closing InputStreamReader", exceptIO);
        }
      }
    }
    /* NOTE: Tools may report a flaw here because buffread and isr are not closed.  Unfortunately, closing those will close System.in, which will cause any future attempts to read from the console to fail and throw an exception */

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE15_External_Control_of_System_or_Configuration_Setting__console_readLine_67b())
        .badSink(dataContainer);
  }
  public void bad(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    String data;

    Logger log_bad = Logger.getLogger("local-logger");

    data = ""; /* init data */

    URLConnection conn = (new URL("http://www.example.org/")).openConnection();
    BufferedReader buffread = null;
    InputStreamReader instrread = null;
    try {
      /* read input from URLConnection */
      instrread = new InputStreamReader(conn.getInputStream());
      buffread = new BufferedReader(instrread);

      data = buffread.readLine(); // This will be reading the first "line" of the response body,
      // which could be very long if there are no newlines in the HTML
    } catch (IOException ioe) {
      log_bad.warning("Error with stream reading");
    } finally {
      /* clean up stream reading objects */
      try {
        if (buffread != null) {
          buffread.close();
        }
      } catch (IOException ioe) {
        log_bad.warning("Error closing buffread");
      } finally {
        try {
          if (instrread != null) {
            instrread.close();
          }
        } catch (IOException ioe) {
          log_bad.warning("Error closing instrread");
        }
      }
    }

    Container data_container = new Container();
    data_container.a = data;
    (new CWE113_HTTP_Response_Splitting__URLConnection_sendRedirectServlet_67b())
        .bad_sink(data_container, request, response);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    short data;

    /* init data */
    data = -1;

    /* POTENTIAL FLAW: Read data from console with readLine*/
    BufferedReader readerBuffered = null;
    InputStreamReader readerInputStream = null;
    try {
      readerInputStream = new InputStreamReader(System.in, "UTF-8");
      readerBuffered = new BufferedReader(readerInputStream);
      String stringNumber = readerBuffered.readLine();
      if (stringNumber != null) {
        data = Short.parseShort(stringNumber.trim());
      }
    } catch (IOException exceptIO) {
      IO.logger.log(Level.WARNING, "Error with stream reading", exceptIO);
    } catch (NumberFormatException exceptNumberFormat) {
      IO.logger.log(Level.WARNING, "Error with number parsing", exceptNumberFormat);
    } finally {
      /* clean up stream reading objects */
      try {
        if (readerBuffered != null) {
          readerBuffered.close();
        }
      } catch (IOException exceptIO) {
        IO.logger.log(Level.WARNING, "Error closing BufferedReader", exceptIO);
      } finally {
        try {
          if (readerInputStream != null) {
            readerInputStream.close();
          }
        } catch (IOException exceptIO) {
          IO.logger.log(Level.WARNING, "Error closing InputStreamReader", exceptIO);
        }
      }
    }

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE190_Integer_Overflow__short_console_readLine_square_67b()).goodB2GSink(dataContainer);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    String data;

    Logger log_bad = Logger.getLogger("local-logger");

    data = ""; /* init data */

    URLConnection conn = (new URL("http://www.example.org/")).openConnection();
    BufferedReader buffread = null;
    InputStreamReader instrread = null;
    try {
      /* read input from URLConnection */
      instrread = new InputStreamReader(conn.getInputStream());
      buffread = new BufferedReader(instrread);

      data = buffread.readLine(); // This will be reading the first "line" of the response body,
      // which could be very long if there are no newlines in the HTML
    } catch (IOException ioe) {
      log_bad.warning("Error with stream reading");
    } finally {
      /* clean up stream reading objects */
      try {
        if (buffread != null) {
          buffread.close();
        }
      } catch (IOException ioe) {
        log_bad.warning("Error closing buffread");
      } finally {
        try {
          if (instrread != null) {
            instrread.close();
          }
        } catch (IOException ioe) {
          log_bad.warning("Error closing instrread");
        }
      }
    }

    Container data_container = new Container();
    data_container.a = data;
    (new CWE643_Unsafe_Treatment_of_XPath_Input__URLConnection_67b()).goodB2G_sink(data_container);
  }
  /* goodB2G() - use badsource and goodsink */
  private void goodB2G() throws Throwable {
    int data;

    Logger log_bad = Logger.getLogger("local-logger");

    /* init data */
    data = -1;

    /* retrieve the "pid" property */
    Properties props = new Properties();
    FileInputStream finstr = null;
    try {
      finstr = new FileInputStream("../common/config.properties");
      props.load(finstr);

      String s_data = props.getProperty("pid");
      data = Integer.parseInt(s_data.trim());
    } catch (IOException ioe) {
      log_bad.warning("Error with stream reading");
    } catch (NumberFormatException nfe) {
      log_bad.warning("Error with number parsing");
    } finally {
      /* clean up stream reading objects */
      try {
        if (finstr != null) {
          finstr.close();
        }
      } catch (IOException ioe) {
        log_bad.warning("Error closing buffread");
      }
    }

    Container data_container = new Container();
    data_container.a = data;
    (new CWE369_Divide_By_Zero__PropertiesFile_divide_67b()).goodB2G_sink(data_container);
  }
  public void bad() throws Throwable {
    int data;

    data = Integer.MIN_VALUE; /* Initialize data */

    /* Read data from a database */
    {
      Connection connection = null;
      PreparedStatement preparedStatement = null;
      ResultSet resultSet = null;

      try {
        /* setup the connection */
        connection = IO.getDBConnection();

        /* prepare and execute a (hardcoded) query */
        preparedStatement = connection.prepareStatement("select name from users where id=0");
        resultSet = preparedStatement.executeQuery();

        /* POTENTIAL FLAW: Read data from a database query resultset */
        String stringNumber = resultSet.getString(1);
        if (stringNumber != null) /* avoid NPD incidental warnings */ {
          try {
            data = Integer.parseInt(stringNumber.trim());
          } catch (NumberFormatException exceptNumberFormat) {
            IO.logger.log(
                Level.WARNING,
                "Number format exception parsing data from string",
                exceptNumberFormat);
          }
        }
      } catch (SQLException exceptSql) {
        IO.logger.log(Level.WARNING, "Error with SQL statement", exceptSql);
      } finally {
        /* Close database objects */
        try {
          if (resultSet != null) {
            resultSet.close();
          }
        } catch (SQLException exceptSql) {
          IO.logger.log(Level.WARNING, "Error closing ResultSet", exceptSql);
        }

        try {
          if (preparedStatement != null) {
            preparedStatement.close();
          }
        } catch (SQLException exceptSql) {
          IO.logger.log(Level.WARNING, "Error closing PreparedStatement", exceptSql);
        }

        try {
          if (connection != null) {
            connection.close();
          }
        } catch (SQLException exceptSql) {
          IO.logger.log(Level.WARNING, "Error closing Connection", exceptSql);
        }
      }
    }

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE191_Integer_Underflow__int_database_multiply_67b()).badSink(dataContainer);
  }
  public void bad() throws Throwable {
    String data;

    Logger log_bad = Logger.getLogger("local-logger");

    data = ""; /* init data */

    Connection conn = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    BufferedReader buffread = null;
    InputStreamReader instrread = null;
    try {
      /* setup the connection */
      conn = IO.getDBConnection();

      /* prepare the query */
      statement = conn.prepareStatement("select name from users where id=?");

      /* get user input for the userid */
      IO.writeLine("Enter a userid to login as (number): ");
      instrread = new InputStreamReader(System.in);
      buffread = new BufferedReader(instrread);
      int num = Integer.parseInt(buffread.readLine());
      statement.setInt(1, num);
      rs = statement.executeQuery();

      data = rs.getString(1);
    } catch (IOException ioe) {
      log_bad.warning("Error with stream reading");
    } finally {
      /* clean up stream reading objects */
      try {
        if (buffread != null) {
          buffread.close();
        }
      } catch (IOException ioe) {
        log_bad.warning("Error closing buffread");
      } finally {
        try {
          if (instrread != null) {
            instrread.close();
          }
        } catch (IOException ioe) {
          log_bad.warning("Error closing instrread");
        }
      }

      /* clean up database objects */
      try {
        if (rs != null) {
          rs.close();
        }
      } catch (SQLException se) {
        log_bad.warning("Error closing rs");
      } finally {
        try {
          if (statement != null) {
            statement.close();
          }
        } catch (SQLException se) {
          log_bad.warning("Error closing statement");
        } finally {
          try {
            if (conn != null) {
              conn.close();
            }
          } catch (SQLException se) {
            log_bad.warning("Error closing conn");
          }
        }
      }
    }

    Container data_container = new Container();
    data_container.a = data;
    (new CWE643_Unsafe_Treatment_of_XPath_Input__fromDB_67b()).bad_sink(data_container);
  }
  public void bad(HttpServletRequest request, HttpServletResponse response) throws Throwable {
    String data;

    Logger log_bad = Logger.getLogger("local-logger");
    data = "";

    /* parse the query string for value of 'id' */
    String id_str = null;
    StringTokenizer st = new StringTokenizer(request.getQueryString(), "&");
    while (st.hasMoreTokens()) {
      String token = st.nextToken();
      int i = token.indexOf("=");
      if ((i > 0) && (i < (token.length() - 1)) && (token.substring(0, i).equals("id"))) {
        id_str = token.substring(i + 1);
        break;
      }
    }

    if (id_str != null) {
      Connection conn = null;
      PreparedStatement statement = null;
      ResultSet rs = null;
      try {
        int id = Integer.parseInt(id_str);
        conn = IO.getDBConnection();
        statement = conn.prepareStatement("select * from pages where id=?");
        /* FLAW: no check to see whether the user has privileges to view the data */
        statement.setInt(1, id);
        rs = statement.executeQuery();
        data = rs.toString();
      } catch (SQLException se) {
        log_bad.warning("Error");
      } finally {
        /* clean up database objects */
        try {
          if (rs != null) {
            rs.close();
          }
        } catch (SQLException se) {
          log_bad.warning("Error closing rs");
        } finally {
          try {
            if (statement != null) {
              statement.close();
            }
          } catch (SQLException se) {
            log_bad.warning("Error closing statement");
          } finally {
            try {
              if (conn != null) {
                conn.close();
              }
            } catch (SQLException se) {
              log_bad.warning("Error closing conn");
            }
          }
        }
      }
    }

    Container data_container = new Container();
    data_container.a = data;
    (new CWE80_XSS__Servlet_getQueryStringServlet_67b())
        .bad_sink(data_container, request, response);
  }
  public void bad() throws Throwable {
    int data;

    data = Integer.MIN_VALUE; /* Initialize data */

    {
      File file = new File("C:\\data.txt");
      FileInputStream streamFileInput = null;
      InputStreamReader readerInputStream = null;
      BufferedReader readerBuffered = null;

      try {
        /* read string from file into data */
        streamFileInput = new FileInputStream(file);
        readerInputStream = new InputStreamReader(streamFileInput, "UTF-8");
        readerBuffered = new BufferedReader(readerInputStream);

        /* POTENTIAL FLAW: Read data from a file */
        /* This will be reading the first "line" of the file, which
         * could be very long if there are little or no newlines in the file */
        String stringNumber = readerBuffered.readLine();
        if (stringNumber != null) /* avoid NPD incidental warnings */ {
          try {
            data = Integer.parseInt(stringNumber.trim());
          } catch (NumberFormatException exceptNumberFormat) {
            IO.logger.log(
                Level.WARNING,
                "Number format exception parsing data from string",
                exceptNumberFormat);
          }
        }
      } catch (IOException exceptIO) {
        IO.logger.log(Level.WARNING, "Error with stream reading", exceptIO);
      } finally {
        /* Close stream reading objects */
        try {
          if (readerBuffered != null) {
            readerBuffered.close();
          }
        } catch (IOException exceptIO) {
          IO.logger.log(Level.WARNING, "Error closing BufferedReader", exceptIO);
        }

        try {
          if (readerInputStream != null) {
            readerInputStream.close();
          }
        } catch (IOException exceptIO) {
          IO.logger.log(Level.WARNING, "Error closing InputStreamReader", exceptIO);
        }

        try {
          if (streamFileInput != null) {
            streamFileInput.close();
          }
        } catch (IOException exceptIO) {
          IO.logger.log(Level.WARNING, "Error closing FileInputStream", exceptIO);
        }
      }
    }

    Container dataContainer = new Container();
    dataContainer.containerOne = data;
    (new CWE129_Improper_Validation_of_Array_Index__File_array_read_no_check_67b())
        .badSink(dataContainer);
  }