mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fix for sql wall
This commit is contained in:
@@ -288,6 +288,20 @@ public class WallVisitorUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = x.getHintsDirect();
|
||||
if (hints != null
|
||||
&& x.getParent() instanceof SQLUnionQuery
|
||||
&& x == ((SQLUnionQuery) x.getParent()).getRight()
|
||||
) {
|
||||
for (SQLCommentHint hint : hints) {
|
||||
String text = hint.getText();
|
||||
if (text.startsWith("!")) {
|
||||
addViolation(visitor, ErrorCode.UNION, "union select hint not allow", x);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SQLExpr where = x.getWhere();
|
||||
if (where != null) {
|
||||
checkCondition(visitor, x.getWhere());
|
||||
|
||||
@@ -44,4 +44,21 @@ public class MySqlWallTest_union extends TestCase {
|
||||
|
||||
Assert.assertTrue(WallUtils.isValidateMySql("select f1, f2 from t where id=1 union select 'u1' as u1, 'u2' as u2", config)); // union select item has alias
|
||||
}
|
||||
|
||||
public void testUnion2() throws Exception
|
||||
{
|
||||
assertFalse(
|
||||
WallUtils.isValidateMySql("SELECT name, surname FROM users WHERE name='' UNION SELECT @@version, 'string1'")
|
||||
);
|
||||
|
||||
assertFalse(
|
||||
WallUtils.isValidateMySql("SELECT name, surname FROM users WHERE name='' UNION SELECT /*! @@version,*/ 'string1'")
|
||||
);
|
||||
|
||||
assertFalse(
|
||||
WallUtils.isValidateMySql("SELECT name, surname FROM users WHERE name=' ' UNION SELECT /*! (select table_name FROM information_schema.tables limit 1,1),*/ 'string1'")
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user