Skip to content
Snippets Groups Projects
Commit 60e27d9b authored by brinn's avatar brinn
Browse files

[BIS-260] Fix SQL injections for custom queries

Add some defensive checks for parameter resolution.

SVN: 27624
parent 309ed4cd
No related branches found
No related tags found
No related merge requests found
...@@ -223,7 +223,11 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO ...@@ -223,7 +223,11 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
for (Entry<String, String> entry : bindingsOrNull.getBindings().entrySet()) for (Entry<String, String> entry : bindingsOrNull.getBindings().entrySet())
{ {
template.bind(entry.getKey(), "?"); template.bind(entry.getKey(), "?");
indexMap.put(template.tryGetIndex(entry.getKey()), entry); final int index = template.tryGetIndex(entry.getKey());
if (index >= 0)
{
indexMap.put(index, entry);
}
} }
} }
final PreparedStatement psm = con.prepareStatement(template.createText()); final PreparedStatement psm = con.prepareStatement(template.createText());
...@@ -231,6 +235,10 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO ...@@ -231,6 +235,10 @@ class DAO extends SimpleJdbcDaoSupport implements IDAO
for (int i = 1; i <= pmd.getParameterCount(); ++i) for (int i = 1; i <= pmd.getParameterCount(); ++i)
{ {
final Entry<String, String> entry = indexMap.get(i - 1); final Entry<String, String> entry = indexMap.get(i - 1);
if (entry == null)
{
throw new SQLDataException("No variable found for for parameter " + i);
}
final String strValue = entry.getValue(); final String strValue = entry.getValue();
try try
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment