Skip to content

Commit

Permalink
sessionctx/variable: fix panic when set variable='' (#9533)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and xiekeyi98 committed Mar 4, 2019
1 parent 0267a7f commit ae91405
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -3594,6 +3595,13 @@ func (s *testIntegrationSuite) TestSetVariables(c *C) {
c.Assert(err, IsNil)
r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`)
r.Check(testkit.Rows("0 0 0 0"))

_, err = tk.Exec("set @@global.max_user_connections='';")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error())
_, err = tk.Exec("set @@global.max_prepared_stmt_count='';")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_prepared_stmt_count").Error())
}

func (s *testIntegrationSuite) TestIssues(c *C) {
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ func ValidateGetSystemVar(name string, isGlobal bool) error {
}

func checkUInt64SystemVar(name, value string, min, max uint64, vars *SessionVars) (string, error) {
if len(value) == 0 {
return value, ErrWrongTypeForVar.GenWithStackByArgs(name)
}
if value[0] == '-' {
_, err := strconv.ParseInt(value, 10, 64)
if err != nil {
Expand Down

0 comments on commit ae91405

Please sign in to comment.