mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql parser & wall
This commit is contained in:
@@ -108,10 +108,20 @@ public class WallConfig implements WallConfigMBean {
|
||||
private boolean conditionOpXorAllow = false;
|
||||
private boolean conditionOpBitwseAllow = true;
|
||||
|
||||
private boolean caseConditionAllow = false;
|
||||
|
||||
public WallConfig(){
|
||||
|
||||
}
|
||||
|
||||
public boolean isCaseConditionAllow() {
|
||||
return caseConditionAllow;
|
||||
}
|
||||
|
||||
public void setCaseConditionAllow(boolean caseConditionAllow) {
|
||||
this.caseConditionAllow = caseConditionAllow;
|
||||
}
|
||||
|
||||
public boolean isConditionDoubleConstAllow() {
|
||||
return conditionDoubleConstAllow;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitorAdapter;
|
||||
@@ -152,6 +153,10 @@ public class SQLServerWallVisitor extends SQLServerASTVisitorAdapter implements
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean visit(SQLServerExecStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLExprTableSource x) {
|
||||
WallVisitorUtils.check(this, x);
|
||||
|
||||
@@ -257,7 +257,7 @@ public class WallVisitorUtils {
|
||||
boolean isSimpleConstExpr = false;
|
||||
SQLExpr first = getFirst(where);
|
||||
|
||||
if (first == where) {
|
||||
if (first == where || first instanceof SQLLiteralExpr) {
|
||||
isSimpleConstExpr = true;
|
||||
} else if (first instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) first;
|
||||
@@ -278,7 +278,6 @@ public class WallVisitorUtils {
|
||||
addViolation(visitor, ErrorCode.ALWAY_TRUE, "select alway true condition not allow", x);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
checkConditionForMultiTenant(visitor, x.getWhere(), x);
|
||||
} finally {
|
||||
@@ -1046,9 +1045,18 @@ public class WallVisitorUtils {
|
||||
return SQLEvalVisitorUtils.eval(dbType, x, Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
if (x instanceof SQLCaseExpr) {
|
||||
if (visitor != null && (!visitor.getConfig().isCaseConditionAllow()) && x instanceof SQLCaseExpr) {
|
||||
SQLCaseExpr caseExpr = (SQLCaseExpr) x;
|
||||
if (caseExpr.getItems().size() > 0) {
|
||||
|
||||
boolean leftIsName = false;
|
||||
if (caseExpr.getParent() instanceof SQLBinaryOpExpr) {
|
||||
SQLExpr left = ((SQLBinaryOpExpr) caseExpr.getParent()).getLeft();
|
||||
if (left instanceof SQLName) {
|
||||
leftIsName = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((!leftIsName) && caseExpr.getItems().size() > 0) {
|
||||
SQLCaseExpr.Item item = caseExpr.getItems().get(0);
|
||||
Object conditionVal = getValue(visitor, item.getConditionExpr());
|
||||
Object itemVal = getValue(visitor, item.getValueExpr());
|
||||
|
||||
Reference in New Issue
Block a user