Skip to content

Commit

Permalink
sessionctx/variable: fix panic when set variable='' (#9533) (#9541)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and shenli committed Mar 4, 2019
1 parent b6a0381 commit ad8e7c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/pingcap/tidb/plan"
"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/terror"
Expand Down Expand Up @@ -3225,6 +3226,10 @@ func (s *testIntegrationSuite) TestSetVariables(c *C) {
_, err = tk.Exec("set global transaction read write;")
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.GenByArgs("max_user_connections").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 @@ -169,6 +169,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.GenByArgs(name)
}
if value[0] == '-' {
_, err := strconv.ParseInt(value, 10, 64)
if err != nil {
Expand Down

0 comments on commit ad8e7c5

Please sign in to comment.