Skip to content

Commit

Permalink
[apache#4211] improvement(catalog-jdbc-mysql): Validated databaseName…
Browse files Browse the repository at this point in the history
… preventing possible SQL injection in MysqlDatabaseOperations.java
  • Loading branch information
ria28 committed Jul 20, 2024
1 parent ba75c86 commit b4e937b
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.*;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.gravitino.StringIdentifier;
Expand Down Expand Up @@ -75,6 +71,7 @@ public String generateCreateDatabaseSql(

@Override
public String generateDropDatabaseSql(String databaseName, boolean cascade) {
validateDatabaseName(databaseName);
final String dropDatabaseSql = "DROP DATABASE `" + databaseName + "`";
if (cascade) {
return dropDatabaseSql;
Expand Down Expand Up @@ -120,4 +117,10 @@ public JdbcSchema load(String databaseName) throws NoSuchSchemaException {
protected boolean isSystemDatabase(String dbName) {
return SYS_MYSQL_DATABASE_NAMES.contains(dbName.toLowerCase(Locale.ROOT));
}

public void validateDatabaseName(String databaseName){
if(Objects.isNull(databaseName) || databaseName.trim().isEmpty()){
throw new IllegalArgumentException("Database name cannot be null or empty.");
}
}
}

0 comments on commit b4e937b

Please sign in to comment.