pT361987 (Community Member) asked a question.

Hello Team, Getting High security flaw which CWE-89 in below line.I added the complete snippet below details .I am thinking code is fine but getting flaw ,please help me to close this issue.
rs = ps.executeQuery(); // At this line showing flaw

public ArrayList runQueryA(String sql, ArrayList<String> params) {

  ResultSet rs = null;

  PreparedStatement ps = null;

  ArrayList arrs = new ArrayList();

  int j = 1;

  Connection conn = null;

  DataSource ds = null;

  try {

 

   Context ctx = new InitialContext();

   ds = (DataSource) ctx.lookup("java:comp/env/jdbc/emochila");

   conn = ds.getConnection();

   ps = conn.prepareStatement(sql);

   for (int i = 0; i < params.size(); i++) {

    ps.setString(j, params.get(i));

    j++;

   }

   rs = ps.executeQuery();

   ResultSetMetaData md = rs.getMetaData();

   int columns = md.getColumnCount();

   while (rs.next()) {

    HashMap row = new HashMap(columns);

    for (int i = 1; i <= columns; ++i) {

     row.put(md.getColumnLabel(i), rs.getString(i));

    }

    arrs.add(row);

   }

 

   try {

    rs.close();

    rs = null;

    ps.close();

    ps = null;

    conn.close();

    conn = null;

   } catch (Exception ex3) {

    logger.error(ex3.getMessage(), ex3);

   }

  } catch (Exception ex) {

   logger.error(ex.getMessage(), ex);

  } finally {

   if (rs != null) {

    try {

     rs.close();

    } catch (SQLException e) {

     logger.error(e.getMessage(), e);

    }

    rs = null;

   }

   if (ps != null) {

    try {

     ps.close();

    } catch (SQLException e) {

     logger.error(e.getMessage(), e);

    }

    ps = null;

   }

   if (conn != null) {

    try {

     conn.close();

    } catch (SQLException e) {

     logger.error(e.getMessage(), e);

    }

    conn = null;

   }

  }

  return arrs;

 }


Topics (3)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.