Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions server/src/com/cloud/configuration/ConfigurationManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ protected void checkIfPodIsDeletable(final long podId) {
dbName = "cloud";
}

String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?";
String selectSql = "SELECT * FROM `?`.`?` WHERE ? = ?";

if(tableName.equals("vm_instance")) {
selectSql += " AND state != '" + VirtualMachine.State.Expunging.toString() + "' AND removed IS NULL";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also move the state to a variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be necessary :)
findbugs is smart enough to check that the returned string is static and cannot be polluted by user input
that's only not the case for other variables that it can't track the origin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering why are we even using a prepareStatement here (and doing a fix to satisfy findbugs). Why dont we use createStatement() and execute sql directly?

Expand All @@ -939,7 +939,10 @@ protected void checkIfPodIsDeletable(final long podId) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
stmt.setLong(1, podId);
stmt.setString(1,dbName);
stmt.setString(2,tableName);
stmt.setString(3,column);
stmt.setLong(4, podId);
final ResultSet rs = stmt.executeQuery();
if (rs != null && rs.next()) {
throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg);
Expand Down Expand Up @@ -1385,7 +1388,7 @@ protected void checkIfZoneIsDeletable(final long zoneId) {

final String dbName = "cloud";

String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?";
String selectSql = "SELECT * FROM `?`.`?` WHERE ? = ?";

if (tableName.equals("op_dc_vnet_alloc")) {
selectSql += " AND taken IS NOT NULL";
Expand All @@ -1410,7 +1413,10 @@ protected void checkIfZoneIsDeletable(final long zoneId) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
stmt.setLong(1, zoneId);
stmt.setString(1,dbName);
stmt.setString(2,tableName);
stmt.setString(3,column);
stmt.setLong(4, zoneId);
final ResultSet rs = stmt.executeQuery();
if (rs != null && rs.next()) {
throw new CloudRuntimeException("The zone is not deletable because " + errorMsg);
Expand Down