Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. package testcases.CWE259_Hard_Coded_Password;
  2.  
  3. import testcasesupport.*;
  4.  
  5. import java.util.logging.Level;
  6. import java.io.*;
  7.  
  8. import java.sql.*;
  9.  
  10. public class connection extends AbstractTestCase
  11. {
  12.     /* uses badsource and badsink */
  13.     public void bad() throws Throwable
  14.     {
  15.         String data;
  16.         if (true)
  17.         {
  18.             data = "7e5tc4s3";
  19.         }
  20.         else
  21.         {
  22.             data = null;
  23.         }
  24.  
  25.         Connection connection = null;
  26.         PreparedStatement preparedStatement = null;
  27.         ResultSet resultSet = null;
  28.  
  29.         if (data != null)
  30.         {
  31.             try
  32.             {
  33.                 connection = DriverManager.getConnection("data-url", "root", data);
  34.                 preparedStatement = connection.prepareStatement("select * from test_table");
  35.                 resultSet = preparedStatement.executeQuery();
  36.             }
  37.             catch (SQLException exceptSql)
  38.             {
  39.                 IO.logger.log(Level.WARNING, "Error with database connection", exceptSql);
  40.             }
  41.             finally
  42.             {
  43.                 try
  44.                 {
  45.                     if (resultSet != null)
  46.                     {
  47.                         resultSet.close();
  48.                     }
  49.                 }
  50.                 catch (SQLException exceptSql)
  51.                 {
  52.                     IO.logger.log(Level.WARNING, "Error closing ResultSet", exceptSql);
  53.                 }
  54.  
  55.                 try
  56.                 {
  57.                     if (preparedStatement != null)
  58.                     {
  59.                         preparedStatement.close();
  60.                     }
  61.                 }
  62.                 catch (SQLException exceptSql)
  63.                 {
  64.                     IO.logger.log(Level.WARNING, "Error closing PreparedStatement", exceptSql);
  65.                 }
  66.  
  67.                 try
  68.                 {
  69.                     if (connection != null)
  70.                     {
  71.                         connection.close();
  72.                     }
  73.                 }
  74.                 catch (SQLException exceptSql)
  75.                 {
  76.                     IO.logger.log(Level.WARNING, "Error closing Connection", exceptSql);
  77.                 }
  78.             }
  79.         }
  80.  
  81.     }
  82.  
  83.  
  84.     public static void main(String[] args) throws ClassNotFoundException,
  85.            InstantiationException, IllegalAccessException
  86.     {
  87.         mainFromParent(args);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement