Patched potential security risk

This commit is contained in:
Marvin Scham
2023-06-28 00:44:07 +02:00
parent f328e00027
commit 187db7e6f5

View File

@@ -369,33 +369,28 @@ public final class SQLiteConnector implements
@Override
public void clearTXData() {
flushTable("transactions");
runDeletionQuery("DELETE FROM transactions;");
}
@Override
public void clearOfferData() {
flushTable("offers");
runDeletionQuery("DELETE FROM offers;");
}
@Override
public void clearProductData() {
flushTable("products");
runDeletionQuery("DELETE FROM products;");
}
/**
* Flushes all data from the specified table.
* Flushes all data using the specified query.
*
* @param table
* @param query
*/
private void flushTable(final String table) {
private void runDeletionQuery(final String query) {
try (Connection connection = db.getConnection();
Statement statement = connection.createStatement()) {
if (table.matches("[\\w]+")) {
String query = "DELETE FROM " + table + ";";
statement.executeUpdate(query);
} else {
throw new PersistenceException("Table name contains illegal characters");
}
statement.executeUpdate(query);
} catch (SQLException e) {
throw new PersistenceException("Something went wrong while clearing the database", e);
}