提交 ee770b4f 编写于 作者: martianzhang's avatar martianzhang

fix #38

  RES.007 select * from tbl where 1;
上级 fd276eb1
...@@ -1228,6 +1228,17 @@ func (q *Query4Audit) RuleImpossibleWhere() Rule { ...@@ -1228,6 +1228,17 @@ func (q *Query4Audit) RuleImpossibleWhere() Rule {
// RuleMeaninglessWhere RES.007 // RuleMeaninglessWhere RES.007
func (q *Query4Audit) RuleMeaninglessWhere() Rule { func (q *Query4Audit) RuleMeaninglessWhere() Rule {
var rule = q.RuleOK() var rule = q.RuleOK()
// SELECT * FROM tb WHERE 1
switch n := q.Stmt.(type) {
case *sqlparser.Select:
if n.Where != nil {
switch n.Where.Expr.(type) {
case *sqlparser.SQLVal:
rule = HeuristicRules["RES.007"]
return rule
}
}
}
// 1=1, 0=0 // 1=1, 0=0
err := sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) { err := sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
switch n := node.(type) { switch n := node.(type) {
...@@ -1266,7 +1277,6 @@ func (q *Query4Audit) RuleMeaninglessWhere() Rule { ...@@ -1266,7 +1277,6 @@ func (q *Query4Audit) RuleMeaninglessWhere() Rule {
} }
return false, nil return false, nil
} }
return true, nil return true, nil
}, q.Stmt) }, q.Stmt)
common.LogIfError(err, "") common.LogIfError(err, "")
......
...@@ -854,6 +854,10 @@ func TestRuleMeaninglessWhere(t *testing.T) { ...@@ -854,6 +854,10 @@ func TestRuleMeaninglessWhere(t *testing.T) {
"select * from tbl where 1 = 1;", "select * from tbl where 1 = 1;",
"select * from tbl where 'a' = 'a';", "select * from tbl where 'a' = 'a';",
"select * from tbl where 'a' != 1;", "select * from tbl where 'a' != 1;",
"select * from tbl where 'a';",
"select * from tbl where 'a' limit 1;",
"select * from tbl where 1;",
"select * from tbl where 1 limit 1;",
}, },
{ {
"select * from tbl where 2 = 1;", "select * from tbl where 2 = 1;",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册