Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider Java v3.0

...

Code Block
bgColor#FFcccc
private Boolean validateValue(long time) {
  // Perform validation
  return true; // If the time is valid	
}

private void storeDateinDB(java.util.Date date) throws SQLException {
  final java.util.Date copy = (java.util.Date)date.clone();
  validateValue(copy.getTime());

  Connection con = DriverManager.getConnection("&quot;jdbc:microsoft:sqlserver://<HOST>&lt;HOST&gt;:1433","<UID>","<PWD>"&quot;,&quot;&lt;UID&gt;&quot;,&quot;&lt;PWD&gt;&quot;);

  PreparedStatement pstmt = con.prepareStatement("&quot;UPDATE ACCESSDB SET TIME = ?"&quot;);
  pstmt.setLong(1, copy.getTime());
  // ...
}	

...

Code Block
bgColor#ccccff
private void storeDateinDB(java.util.Date date) throws SQLException {
  final java.util.Date copy = new java.util.Date();
  validateValue(copy.getTime());

  Connection con = DriverManager.getConnection("&quot;jdbc:microsoft:sqlserver://<HOST>&lt;HOST&gt;:1433","<UID>","<PWD>"&quot;,&quot;&lt;UID&gt;&quot;,&quot;&lt;PWD&gt;&quot;);

  PreparedStatement pstmt = con.prepareStatement("&quot;UPDATE ACCESSDB SET TIME = ?"&quot;);
  pstmt.setLong(1, copy.getTime());
  // ...
}	

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

Wiki Markup
\[[Sterbenz 06|AA. Java References#Sterbenz 06]\] 

...

MET37-J. Do not call overridable methods from a privileged block      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;12. Methods (MET)      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MET35-J. Ensure that the clone method calls super.clone