Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wenshao/druid
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 1, 2014
2 parents 0d15cca + 59d357a commit df179b2
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 108 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>0.2.27-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>

<packaging>jar</packaging>
<name>druid</name>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/alibaba/druid/VERSION.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

public final class VERSION {

public final static int MajorVersion = 0;
public final static int MinorVersion = 2;
public final static int RevisionVersion = 27;
public final static int MajorVersion = 1;
public final static int MinorVersion = 0;
public final static int RevisionVersion = 2;

public static String getVersionNumber() {
return VERSION.MajorVersion + "." + VERSION.MinorVersion + "." + VERSION.RevisionVersion;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/alibaba/druid/pool/DruidDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ private DruidPooledConnection getConnectionInternal(long maxWait) throws SQLExce

String errorMessage = buf.toString();

if (this.createError == null) {
if (this.createError != null) {
throw new GetConnectionTimeoutException(errorMessage, createError);
} else {
throw new GetConnectionTimeoutException(errorMessage);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/alibaba/druid/sql/SQLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ public static String buildToDate(String columnName, String tableAlias, String pa

public static List<SQLExpr> split(SQLBinaryOpExpr x) {
List<SQLExpr> groupList = new ArrayList<SQLExpr>();
groupList.add(x.getRight());

SQLExpr left = x.getLeft();
for (;;) {
if (left instanceof SQLBinaryOpExpr && ((SQLBinaryOpExpr) left).getOperator() == x.getOperator()) {
Expand All @@ -321,7 +323,6 @@ public static List<SQLExpr> split(SQLBinaryOpExpr x) {
break;
}
}
groupList.add(x.getRight());
return groupList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,12 @@ public static boolean visit(SQLEvalVisitor visitor, SQLBinaryOpExpr x) {
wallConditionContext.setPartAlwayTrue(true);
}
}
} else if (x.getOperator() == SQLBinaryOperator.BooleanAnd) {
if (wallConditionContext != null) {
if (left.getAttribute(EVAL_VALUE) == Boolean.FALSE || right.getAttribute(EVAL_VALUE) == Boolean.FALSE) {
wallConditionContext.setPartAlwayFalse(true);
}
}
} else if (x.getOperator() == SQLBinaryOperator.BooleanXor) {
if (wallConditionContext != null) {
wallConditionContext.setXor(true);
Expand Down
175 changes: 92 additions & 83 deletions src/main/java/com/alibaba/druid/wall/WallConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,80 +24,81 @@

public class WallConfig implements WallConfigMBean {

private boolean noneBaseStatementAllow = false;

private boolean callAllow = true;
private boolean selelctAllow = true;
private boolean selectIntoAllow = true;
private boolean selectIntoOutfileAllow = false;
private boolean selectWhereAlwayTrueCheck = true;
private boolean selectHavingAlwayTrueCheck = true;
private boolean selectUnionCheck = true;
private boolean selectMinusCheck = true;
private boolean selectExceptCheck = true;
private boolean selectIntersectCheck = true;
private boolean createTableAllow = true;
private boolean dropTableAllow = true;
private boolean alterTableAllow = true;

private boolean conditionAndAlwayTrueAllow = false;
private boolean conditionDoubleConstAllow = false;
private boolean conditionLikeTrueAllow = true;

private boolean selectAllColumnAllow = true;

private boolean deleteAllow = true;
private boolean deleteWhereAlwayTrueCheck = true;
private boolean deleteWhereNoneCheck = false;

private boolean updateAllow = true;
private boolean updateWhereAlayTrueCheck = true;
private boolean updateWhereNoneCheck = false;

private boolean insertAllow = true;
private boolean mergeAllow = true;
private boolean minusAllow = true;
private boolean intersectAllow = true;
private boolean replaceAllow = true;
private boolean setAllow = true;
private boolean commitAllow = true;
private boolean rollbackAllow = true;
private boolean useAllow = true;

private boolean multiStatementAllow = false;

private boolean truncateAllow = true;

private boolean commentAllow = false;
private boolean strictSyntaxCheck = true;
private boolean constArithmeticAllow = true;
private boolean limitZeroAllow = false;

private boolean describeAllow = true;
private boolean showAllow = true;

private boolean schemaCheck = true;
private boolean tableCheck = true;
private boolean functionCheck = true;
private boolean objectCheck = true;
private boolean variantCheck = true;

private boolean mustParameterized = false;

private boolean doPrivilegedAllow = false;

protected final Set<String> denyFunctions = new ConcurrentSkipListSet<String>();
protected final Set<String> denyTables = new ConcurrentSkipListSet<String>();
protected final Set<String> denySchemas = new ConcurrentSkipListSet<String>();
protected final Set<String> denyVariants = new ConcurrentSkipListSet<String>();
protected final Set<String> denyObjects = new ConcurrentSkipListSet<String>();

protected final Set<String> permitFunctions = new ConcurrentSkipListSet<String>();
protected final Set<String> permitTables = new ConcurrentSkipListSet<String>();
protected final Set<String> permitSchemas = new ConcurrentSkipListSet<String>();
protected final Set<String> permitVariants = new ConcurrentSkipListSet<String>();

protected final Set<String> readOnlyTables = new ConcurrentSkipListSet<String>();
private boolean noneBaseStatementAllow = false;

private boolean callAllow = true;
private boolean selelctAllow = true;
private boolean selectIntoAllow = true;
private boolean selectIntoOutfileAllow = false;
private boolean selectWhereAlwayTrueCheck = true;
private boolean selectHavingAlwayTrueCheck = true;
private boolean selectUnionCheck = true;
private boolean selectMinusCheck = true;
private boolean selectExceptCheck = true;
private boolean selectIntersectCheck = true;
private boolean createTableAllow = true;
private boolean dropTableAllow = true;
private boolean alterTableAllow = true;

private boolean conditionAndAlwayTrueAllow = false;
private boolean conditionAndAlwayFalseAllow = false;
private boolean conditionDoubleConstAllow = false;
private boolean conditionLikeTrueAllow = true;

private boolean selectAllColumnAllow = true;

private boolean deleteAllow = true;
private boolean deleteWhereAlwayTrueCheck = true;
private boolean deleteWhereNoneCheck = false;

private boolean updateAllow = true;
private boolean updateWhereAlayTrueCheck = true;
private boolean updateWhereNoneCheck = false;

private boolean insertAllow = true;
private boolean mergeAllow = true;
private boolean minusAllow = true;
private boolean intersectAllow = true;
private boolean replaceAllow = true;
private boolean setAllow = true;
private boolean commitAllow = true;
private boolean rollbackAllow = true;
private boolean useAllow = true;

private boolean multiStatementAllow = false;

private boolean truncateAllow = true;

private boolean commentAllow = false;
private boolean strictSyntaxCheck = true;
private boolean constArithmeticAllow = true;
private boolean limitZeroAllow = false;

private boolean describeAllow = true;
private boolean showAllow = true;

private boolean schemaCheck = true;
private boolean tableCheck = true;
private boolean functionCheck = true;
private boolean objectCheck = true;
private boolean variantCheck = true;

private boolean mustParameterized = false;

private boolean doPrivilegedAllow = false;

protected final Set<String> denyFunctions = new ConcurrentSkipListSet<String>();
protected final Set<String> denyTables = new ConcurrentSkipListSet<String>();
protected final Set<String> denySchemas = new ConcurrentSkipListSet<String>();
protected final Set<String> denyVariants = new ConcurrentSkipListSet<String>();
protected final Set<String> denyObjects = new ConcurrentSkipListSet<String>();

protected final Set<String> permitFunctions = new ConcurrentSkipListSet<String>();
protected final Set<String> permitTables = new ConcurrentSkipListSet<String>();
protected final Set<String> permitSchemas = new ConcurrentSkipListSet<String>();
protected final Set<String> permitVariants = new ConcurrentSkipListSet<String>();

protected final Set<String> readOnlyTables = new ConcurrentSkipListSet<String>();

private String dir;

Expand All @@ -106,24 +107,24 @@ public class WallConfig implements WallConfigMBean {
private String tenantTablePattern;
private String tenantColumn;

private boolean wrapAllow = true;
private boolean metadataAllow = true;
private boolean wrapAllow = true;
private boolean metadataAllow = true;

private boolean conditionOpXorAllow = false;
private boolean conditionOpBitwseAllow = true;
private boolean conditionOpXorAllow = false;
private boolean conditionOpBitwseAllow = true;

private boolean caseConditionAllow = false;
private boolean caseConditionConstAllow = false;

public WallConfig(){

}

public boolean isCaseConditionAllow() {
return caseConditionAllow;
public boolean isCaseConditionConstAllow() {
return caseConditionConstAllow;
}

public void setCaseConditionAllow(boolean caseConditionAllow) {
this.caseConditionAllow = caseConditionAllow;
public void setCaseConditionConstAllow(boolean caseConditionConstAllow) {
this.caseConditionConstAllow = caseConditionConstAllow;
}

public boolean isConditionDoubleConstAllow() {
Expand Down Expand Up @@ -158,6 +159,14 @@ public void setConditionAndAlwayTrueAllow(boolean conditionAndAlwayTrueAllow) {
this.conditionAndAlwayTrueAllow = conditionAndAlwayTrueAllow;
}

public boolean isConditionAndAlwayFalseAllow() {
return conditionAndAlwayFalseAllow;
}

public void setConditionAndAlwayFalseAllow(boolean conditionAndAlwayFalseAllow) {
this.conditionAndAlwayFalseAllow = conditionAndAlwayFalseAllow;
}

public boolean isUseAllow() {
return useAllow;
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/alibaba/druid/wall/spi/MySqlWallVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.WallSqlTableStat;
import com.alibaba.druid.wall.WallVisitor;
import com.alibaba.druid.wall.spi.WallVisitorUtils.WallTopStatementContext;
import com.alibaba.druid.wall.violation.ErrorCode;
import com.alibaba.druid.wall.violation.IllegalSQLObjectViolation;

Expand Down Expand Up @@ -310,6 +311,13 @@ public boolean visit(SQLVariantRefExpr x) {
}

if (varName.startsWith("@@") && !checkVar(x.getParent(), x.getName())) {

final WallTopStatementContext topStatementContext = WallVisitorUtils.getWallTopStatementContext();
if (topStatementContext != null
&& (topStatementContext.fromSysSchema() || topStatementContext.fromSysTable())) {
return false;
}

boolean isTop = WallVisitorUtils.isTopNoneFromSelect(this, x);
if (!isTop) {
boolean allow = true;
Expand Down Expand Up @@ -346,7 +354,7 @@ public boolean visit(SQLExprTableSource x) {

@Override
public boolean visit(MySqlOutFileExpr x) {
if (!config.isSelectIntoOutfileAllow()) {
if (!config.isSelectIntoOutfileAllow() && !WallVisitorUtils.isTopSelectOutFile(x)) {
violations.add(new IllegalSQLObjectViolation(ErrorCode.INTO_OUTFILE, "into out file not allow", toSQL(x)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallProvider;
import com.alibaba.druid.wall.WallVisitor;
import com.alibaba.druid.wall.spi.WallVisitorUtils.WallTopStatementContext;
import com.alibaba.druid.wall.violation.ErrorCode;
import com.alibaba.druid.wall.violation.IllegalSQLObjectViolation;

Expand Down Expand Up @@ -254,6 +255,12 @@ public boolean visit(SQLVariantRefExpr x) {

if (config.isVariantCheck() && varName.startsWith("@@")) {

final WallTopStatementContext topStatementContext = WallVisitorUtils.getWallTopStatementContext();
if (topStatementContext != null
&& (topStatementContext.fromSysSchema() || topStatementContext.fromSysTable())) {
return false;
}

boolean allow = true;
if (WallVisitorUtils.isWhereOrHaving(x) && isDeny(varName)) {
allow = false;
Expand Down
Loading

0 comments on commit df179b2

Please sign in to comment.